]> Some of my projects - localmylist.git/commitdiff
Add new tab showing current Pending Requests.
authorAPTX <marek321@gmail.com>
Sun, 2 Jun 2013 23:44:25 +0000 (01:44 +0200)
committerAPTX <marek321@gmail.com>
Sun, 2 Jun 2013 23:44:25 +0000 (01:44 +0200)
localmylist-management/localmylist-management.pro
localmylist-management/registertabs.cpp
localmylist-management/tabs/pendingrequesttab.cpp [new file with mode: 0644]
localmylist-management/tabs/pendingrequesttab.h [new file with mode: 0644]
localmylist-management/tabs/pendingrequesttab.ui [new file with mode: 0644]
localmylist/database.cpp
localmylist/database.h

index 78845bc6bab0183485ea3bc4cb17be471cddbd68..60ca22bfa11a4411ef61d9c3e7534c5697c1deb1 100644 (file)
@@ -24,6 +24,7 @@ SOURCES += main.cpp\
        tabs/searchtab.cpp \
        tabs/reportstab.cpp \
        tabs/unknownfilestab.cpp \
+       tabs/pendingrequesttab.cpp \
        registertabs.cpp
 
 HEADERS += mainwindow.h \
index 41e7efb3f5f5c26486a6e78f704b6758ca0ea167..1039af1384be99207b00226d39ac1b437371089e 100644 (file)
@@ -3,6 +3,7 @@
 #include "tabs/searchtab.h"
 #include "tabs/reportstab.h"
 #include "tabs/unknownfilestab.h"
+#include "tabs/pendingrequesttab.h"
 
 void registerTabs()
 {
@@ -10,4 +11,5 @@ void registerTabs()
        TabWidget::registerTab<SearchTab>();
        TabWidget::registerTab<ReportsTab>();
        TabWidget::registerTab<UnknownFilesTab>();
+       TabWidget::registerTab<PendingRequestTab>();
 }
diff --git a/localmylist-management/tabs/pendingrequesttab.cpp b/localmylist-management/tabs/pendingrequesttab.cpp
new file mode 100644 (file)
index 0000000..ee1d5e2
--- /dev/null
@@ -0,0 +1,125 @@
+#include "pendingrequesttab.h"
+#include "ui_pendingrequesttab.h"
+
+#include <QSqlQueryModel>
+
+#include "mylist.h"
+#include "database.h"
+
+PendingRequestTab::PendingRequestTab(QWidget *parent) :
+       AbstractTabBase(parent),
+       ui(new Ui::PendingRequestTab)
+{
+       ui->setupUi(this);
+       setLabel(name());
+}
+
+PendingRequestTab::~PendingRequestTab()
+{
+       delete ui;
+}
+
+QString PendingRequestTab::staticId()
+{
+       return "pending_request";
+}
+
+QString PendingRequestTab::name()
+{
+       return tr("Pending Requests");
+}
+
+void PendingRequestTab::init()
+{
+       model = new QSqlQueryModel(this);
+       ui->view->setSelectionBehavior(QAbstractItemView::SelectRows);
+
+       connect(ui->retryButton, SIGNAL(clicked()), this, SLOT(resetFailCount()));
+       connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteSelected()));
+}
+
+void PendingRequestTab::activate()
+{
+       reload();
+}
+
+void PendingRequestTab::reload()
+{
+       QSqlQuery &q = LocalMyList::instance()->database()->prepare(
+       "SELECT aid, eid, fid, ed2k, size, "
+       "               added, start, failed, connection_error_count, data_error_count "
+       "       FROM pending_request "
+       "       ORDER BY added ASC, start ASC ");
+
+       LocalMyList::instance()->database()->exec(q);
+       model->setQuery(q);
+       ui->view->setModel(model);
+       ui->view->resizeColumnsToContents();
+}
+
+void PendingRequestTab::selectAll()
+{
+       ui->view->selectAll();
+}
+
+void PendingRequestTab::clearSelection()
+{
+       ui->view->clearSelection();
+}
+
+void PendingRequestTab::deleteSelected()
+{
+       QList<LocalMyList::PendingRequest> requests = selectionToPendingRequestList();
+
+       if (!requests.count())
+               return;
+
+       {
+               LocalMyList::RaiiTransaction t(LocalMyList::instance()->database());
+               for (const LocalMyList::PendingRequest &request : requests)
+               {
+                       LocalMyList::instance()->database()->clearRequest(request);
+               }
+               t.commit();
+       }
+
+       reload();
+}
+
+void PendingRequestTab::resetFailCount()
+{
+       QList<LocalMyList::PendingRequest> requests = selectionToPendingRequestList();
+
+       if (!requests.count())
+               return;
+
+       {
+               LocalMyList::RaiiTransaction t(LocalMyList::instance()->database());
+               for (const LocalMyList::PendingRequest &request : requests)
+               {
+                       LocalMyList::instance()->database()->resetPendingRequestErrorCount(request);
+               }
+               t.commit();
+       }
+       reload();
+}
+
+QList<LocalMyList::PendingRequest> PendingRequestTab::selectionToPendingRequestList()
+{
+       QList<LocalMyList::PendingRequest> ret;
+       QModelIndexList selection = ui->view->selectionModel()->selectedRows();
+
+       for (const QModelIndex &idx : selection)
+       {
+               LocalMyList::PendingRequest pr;
+               pr.aid = idx.data().toInt();
+               pr.eid = model->data(model->index(idx.row(), 1)).toInt();
+               pr.fid = model->data(model->index(idx.row(), 2)).toInt();
+               pr.ed2k = model->data(model->index(idx.row(), 3)).toByteArray();
+               pr.size = model->data(model->index(idx.row(), 4)).toLongLong();
+
+               ret << pr;
+       }
+
+       return ret;
+}
diff --git a/localmylist-management/tabs/pendingrequesttab.h b/localmylist-management/tabs/pendingrequesttab.h
new file mode 100644 (file)
index 0000000..0ac5603
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef PENDINGREQUESTTAB_H
+#define PENDINGREQUESTTAB_H
+
+#include "abstracttab.h"
+#include "databaseclasses.h"
+
+class QSqlQueryModel;
+
+namespace Ui {
+class PendingRequestTab;
+}
+
+class PendingRequestTab : public AbstractTabBase<PendingRequestTab>
+{
+       Q_OBJECT
+
+public:
+       explicit PendingRequestTab(QWidget *parent = 0);
+       ~PendingRequestTab();
+
+       static QString staticId();
+       static QString name();
+
+       void init();
+       void activate();
+
+       void reload();
+       void selectAll();
+       void clearSelection();
+
+public slots:
+       void deleteSelected();
+       void resetFailCount();
+
+private:
+       QList<LocalMyList::PendingRequest> selectionToPendingRequestList();
+
+       Ui::PendingRequestTab *ui;
+
+       QSqlQueryModel *model;
+};
+
+#endif // PENDINGREQUESTTAB_H
diff --git a/localmylist-management/tabs/pendingrequesttab.ui b/localmylist-management/tabs/pendingrequesttab.ui
new file mode 100644 (file)
index 0000000..ddb8bdb
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PendingRequestTab</class>
+ <widget class="QWidget" name="PendingRequestTab">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>864</width>
+    <height>552</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QTableView" name="view"/>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QPushButton" name="selectAllButton">
+       <property name="text">
+        <string>Select All</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="clearSelectionButton">
+       <property name="text">
+        <string>Clear Selection</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>For Selected:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="retryButton">
+       <property name="text">
+        <string>Reset Fail Count</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="deleteButton">
+       <property name="text">
+        <string>Delete</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index f3665314f4882b8846c5c0a00278cc99f0867ee2..467738c34347fdcaa8fcc46cc2fd2b960705646e 100644 (file)
@@ -1423,6 +1423,27 @@ bool Database::clearPendingRequestDataErrors()
        return true;
 }
 
+bool Database::resetPendingRequestErrorCount(const PendingRequest &request)
+{
+       QSqlQuery &q = prepare(
+       "UPDATE pending_request "
+       "       SET start = NULL, failed = NULL, "
+       "               connection_error_count = 0, "
+       "               data_error_count = 0 "
+       "       WHERE aid = :aid "
+       "               AND eid = :eid "
+       "               AND fid = :fid "
+       "               AND ed2k = :ed2k "
+       "               AND size = :size ");
+       q.bindValue(":aid", request.aid);
+       q.bindValue(":eid", request.eid);
+       q.bindValue(":fid", request.fid);
+       q.bindValue(":ed2k", (request.ed2k.isNull() ? QByteArray("") : request.ed2k).constData());
+       q.bindValue(":size", request.size);
+
+       return exec(q);
+}
+
 bool Database::clearFailedPendingMyListUpdateRequests(int minutes)
 {
        QSqlQuery &q = prepare(
index 5a7d2519505f8abd0909832e7f3028f0d9b9b47e..466963615d62622bffe2e3b9e323a84db4eed423 100644 (file)
@@ -120,6 +120,7 @@ public slots:
        // TODO these are named wrong
        bool clearPendingRequestConnectionErrors(int minutes = 10);
        bool clearPendingRequestDataErrors();
+       bool resetPendingRequestErrorCount(const LocalMyList::PendingRequest &request);
 
        bool clearFailedPendingMyListUpdateRequests(int minutes = 10);