From ae1f145e171ceb043d5956d60c9b79ca6a52fc1c Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 28 Feb 2016 02:33:25 +0100 Subject: [PATCH] small fixes --- alpm/alpmdatabase.cpp | 7 +++++-- alpm/manager.cpp | 4 ++-- alpm/manager.h | 14 +++++++------- gui/main.cpp | 10 +++++----- gui/mainwindow.cpp | 30 +++++++++++++++++++++++------- gui/mainwindow.h | 7 ++++++- web/js/packagemanagement.js | 19 ++++++++++++++----- web/js/pagination.js | 4 +--- web/js/tabbing.js | 4 +--- web/js/utils.js | 4 +++- 10 files changed, 67 insertions(+), 36 deletions(-) diff --git a/alpm/alpmdatabase.cpp b/alpm/alpmdatabase.cpp index b4ccb0a..7fa72e1 100644 --- a/alpm/alpmdatabase.cpp +++ b/alpm/alpmdatabase.cpp @@ -259,7 +259,6 @@ std::unique_ptr AlpmDatabase::emptyPackage() */ void AlpmDatabase::databaseDownloadFinished() { - removeBusyFlag(); auto *reply = static_cast(sender()); reply->deleteLater(); bool filesDatabase = reply->property("filesDatabase").toBool(); @@ -274,6 +273,7 @@ void AlpmDatabase::databaseDownloadFinished() if(!QFile::rename(newDatabasePath, backupFile)) { cerr << "An IO error occured when storing database file for [" << name().toLocal8Bit().data() << "]: Unable to rename present database file." << endl; reply = nullptr; + removeBusyFlag(); return; } } @@ -285,10 +285,11 @@ void AlpmDatabase::databaseDownloadFinished() QWriteLocker locker(lock()); m_dbPath = newDatabasePath; } - initAsSoonAsPossible(); + init(); } else { locker.relock(); cerr << "An IO error occured when storing database file for [" << name().toLocal8Bit().data() << "]: Unable to create/write output file." << endl; + removeBusyFlag(); } } else { cerr << "An error occured when dwonloading database file for [" << name().toLocal8Bit().data() << "]: " << reply->errorString().toLocal8Bit().data() << endl; @@ -296,6 +297,8 @@ void AlpmDatabase::databaseDownloadFinished() cerr << "-> Attempting to download regular database file instead of files database file." << endl; locker.unlock(); downloadDatabase(m_downloadTargetDir, false); + } else { + removeBusyFlag(); } } } diff --git a/alpm/manager.cpp b/alpm/manager.cpp index 41d0215..69d12e1 100644 --- a/alpm/manager.cpp +++ b/alpm/manager.cpp @@ -498,8 +498,8 @@ void Manager::initAlpmDataBases() if(localDatabase()) { loaders << static_cast(localDatabase()->init()); } - for(auto &syncDbEntry : m_syncDbMap) { - loaders << static_cast(syncDbEntry.second->init()); + for(auto &syncDb : m_syncDbs) { + loaders << static_cast(syncDb->init()); } for(auto *loader : loaders) { if(loader) { diff --git a/alpm/manager.h b/alpm/manager.h index 55e69ef..aeee60f 100644 --- a/alpm/manager.h +++ b/alpm/manager.h @@ -58,17 +58,17 @@ public: void setWriteCacheBeforeGone(bool writeCacheBeforeGone); bool isAutoCacheMaintenanceEnabled() const; void setAutoCacheMaintenanceEnabled(bool enabled); - void writeCache(); - void restoreCache(); - void cleanCache(); - void wipeCache(); - void maintainCache(); + Q_SLOT void writeCache(); + Q_SLOT void restoreCache(); + Q_SLOT void cleanCache(); + Q_SLOT void wipeCache(); + Q_SLOT void maintainCache(); // updating bool isAutoUpdateEnabled() const; void setAutoUpdateEnabled(bool enabled); - void updateAlpmDatabases(); - void forceUpdateAlpmDatabases(); + Q_SLOT void updateAlpmDatabases(); + Q_SLOT void forceUpdateAlpmDatabases(); // package lookup AlpmPackage *packageFromDatabase(const QString &dbName, const QString &pkgName); diff --git a/gui/main.cpp b/gui/main.cpp index 52c0e0b..aa4f226 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) { // configure Qt qtConfigArgs.applySettings(); + QApplication application(argc, argv); // find directory with web files QString webdir; @@ -67,11 +68,6 @@ int main(int argc, char *argv[]) webdir = QStringLiteral("/usr/share/" PROJECT_NAME "/web"); } - // create app - QApplication application(argc, argv); - MainWindow mainWindow(webdir); - mainWindow.show(); - // setup manager Manager manager(config); cerr << shchar << "Loading databases ..." << endl; @@ -89,6 +85,10 @@ int main(int argc, char *argv[]) manager.setAutoCacheMaintenanceEnabled(true); manager.setAutoUpdateEnabled(true); + // create app + MainWindow mainWindow(webdir, &manager); + mainWindow.show(); + // run Qt event loop return application.exec(); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 96ade1d..da61204 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1,6 +1,8 @@ #include "./mainwindow.h" #include "./webpage.h" +#include "../alpm/manager.h" + #include "resources/config.h" #include @@ -17,7 +19,9 @@ namespace RepoIndex { /*! * \brief Constructs a new main window. */ -MainWindow::MainWindow(const QString &webdir) +MainWindow::MainWindow(const QString &webdir, Manager *manager) : + m_manager(manager), + m_contextMenu(nullptr) { QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); setWindowTitle(QStringLiteral(APP_NAME)); @@ -79,12 +83,24 @@ bool MainWindow::event(QEvent *event) */ void MainWindow::showInfoWebViewContextMenu(const QPoint &) { - QAction copyAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy"), nullptr); - copyAction.setDisabled(m_webView.selectedText().isEmpty()); - connect(©Action, &QAction::triggered, this, &MainWindow::copyInfoWebViewSelection); - QMenu menu; - menu.addAction(©Action); - menu.exec(QCursor::pos()); + if(!m_contextMenu) { + m_contextMenu = new QMenu(this); + auto *reloadAction = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), tr("Reload UI"), m_contextMenu); + connect(reloadAction, &QAction::triggered, &m_webView, &WEB_VIEW_PROVIDER::reload); + m_copyAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy"), m_contextMenu); + connect(m_copyAction, &QAction::triggered, this, &MainWindow::copyInfoWebViewSelection); + auto *updateAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-download")), tr("Update sync-databases"), m_contextMenu); + connect(updateAction, &QAction::triggered, m_manager, &Manager::forceUpdateAlpmDatabases); + auto *wipeCacheAction = new QAction(QIcon::fromTheme(QStringLiteral("document-revert")), tr("Wipe cached packages"), m_contextMenu); + connect(wipeCacheAction, &QAction::triggered, m_manager, &Manager::wipeCache); + m_contextMenu->addAction(m_copyAction); + m_contextMenu->addAction(reloadAction); + m_contextMenu->addSeparator(); + m_contextMenu->addAction(updateAction); + m_contextMenu->addAction(wipeCacheAction); + } + m_copyAction->setDisabled(m_webView.selectedText().isEmpty()); + m_contextMenu->exec(QCursor::pos()); } /*! diff --git a/gui/mainwindow.h b/gui/mainwindow.h index ec4b0a0..3d31483 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -12,11 +12,13 @@ namespace RepoIndex { +class Manager; + class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(const QString &webdir); + MainWindow(const QString &webdir, Manager *manager); protected: bool event(QEvent *event); @@ -26,7 +28,10 @@ private slots: void copyInfoWebViewSelection(); private: + Manager *m_manager; WEB_VIEW_PROVIDER m_webView; + QMenu *m_contextMenu; + QAction *m_copyAction; }; } diff --git a/web/js/packagemanagement.js b/web/js/packagemanagement.js index 37f2618..9c7d711 100644 --- a/web/js/packagemanagement.js +++ b/web/js/packagemanagement.js @@ -16,8 +16,17 @@ if(color) { this.rowElement.style.backgroundColor = color; } - this.rowElement.onclick = function(e) { - repoindex.pageManager.packageManager.showPackageInfoForIndex(this.entry.index, typeof e === "object" && e.button === 1); + this.rowElement.onmousedown = function(e) { + if(!repoindex.isFirefox) { + repoindex.pageManager.packageManager.showPackageInfoForIndex(this.entry.index, typeof e === "object" && (e.button === 1 || e.button === 2)); + } + }; + this.rowElement.oncontextmenu = function(e) { + e.preventDefault(); + // Firefox doesn't support properly support mouse events -> use context menu event to show package info + if(repoindex.isFirefox) { + repoindex.pageManager.packageManager.showPackageInfoForIndex(this.entry.index, true); + } }; this.initTableRow = function() { @@ -155,6 +164,9 @@ repoindex.addField(tb, "Repository", repoindex.makeStr(entry.info.repo)); } repoindex.addField(tb, "Version", repoindex.makeStr(basics.ver)); + if(basics.fdate) { + repoindex.addField(tb, "Out-of-date", "since " + repoindex.makeStr(basics.fdate)).style.color = "red"; + } repoindex.addField(tb, "Description", repoindex.makeStr(basics.desc)); if(basics.arch) { repoindex.addField(tb, "Architecture", repoindex.makeStr(basics.arch)); @@ -204,9 +216,6 @@ if(details.main) { repoindex.addField(tb, "Maintainer", repoindex.makeStr(details.main)); } - if(basics.flagdate) { - repoindex.addField(tb, "Out-of-date", repoindex.makeStr(basics.flagdate)); - } if(details.fsub) { repoindex.addField(tb, "First submitted", repoindex.makeStr(details.fsub)); } diff --git a/web/js/pagination.js b/web/js/pagination.js index 0d8b411..fd51d86 100644 --- a/web/js/pagination.js +++ b/web/js/pagination.js @@ -1,8 +1,6 @@ var repoindex = (function(repoindex) { - /*! - * \brief Adds a bootstrap pagination to the HTML element with the specified id. - */ + // Adds a bootstrap pagination to the HTML element with the specified id repoindex.Pagination = function(containerId) { // basic initialization this.containerId = containerId; diff --git a/web/js/tabbing.js b/web/js/tabbing.js index a9db54b..2f0bb31 100644 --- a/web/js/tabbing.js +++ b/web/js/tabbing.js @@ -1,8 +1,6 @@ var repoindex = (function(repoindex) { - /*! - * \brief Adds bootstrap tabs to the HTML element with the specified id. - */ + // Adds bootstrap tabs to the HTML element with the specified id. repoindex.Tabbing = function(containerId) { // assemble required element structure this.containerElement = document.createElement("div"); diff --git a/web/js/utils.js b/web/js/utils.js index 8b1a08f..243f7b7 100644 --- a/web/js/utils.js +++ b/web/js/utils.js @@ -385,7 +385,9 @@ return function() { func.call(obj, args); } - } + }; + + repoindex.isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1; return repoindex;