From 07912d230b4735cdc55346f58883fe2676ada3cd Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Wed, 10 Jun 2015 21:27:11 +0000 Subject: [PATCH] Use PascalCase for Qt client filenames Split FileTree.{h,cc} and FilterBar.{h,cc} files so that each class is in its own file. This breaks translations (some classes got renamed => context changed), to be fixed by next commit (along with Tx sync). --- qt/{about.cc => AboutDialog.cc} | 6 +- qt/{about.h => AboutDialog.h} | 10 +- qt/{about.ui => AboutDialog.ui} | 0 qt/{add-data.cc => AddData.cc} | 6 +- qt/{add-data.h => AddData.h} | 8 +- qt/{app.cc => Application.cc} | 60 +- qt/{app.h => Application.h} | 24 +- qt/CMakeLists.txt | 182 +-- qt/{column-resizer.cc => ColumnResizer.cc} | 2 +- qt/{column-resizer.h => ColumnResizer.h} | 2 +- qt/{types.h => CustomVariantType.h} | 6 +- qt/{dbus-adaptor.cc => DBusAdaptor.cc} | 14 +- qt/{dbus-adaptor.h => DBusAdaptor.h} | 16 +- qt/{details.cc => DetailsDialog.cc} | 94 +- qt/{details.h => DetailsDialog.h} | 18 +- qt/{details.ui => DetailsDialog.ui} | 4 +- qt/{favicon.cc => FaviconCache.cc} | 24 +- qt/{favicon.h => FaviconCache.h} | 22 +- qt/FileTreeDelegate.cc | 90 ++ qt/FileTreeDelegate.h | 28 + qt/FileTreeItem.cc | 386 +++++++ qt/FileTreeItem.h | 83 ++ qt/FileTreeModel.cc | 386 +++++++ qt/FileTreeModel.h | 90 ++ qt/FileTreeView.cc | 167 +++ qt/FileTreeView.h | 54 + qt/FilterBar.cc | 410 +++++++ qt/{filterbar.h => FilterBar.h} | 71 +- qt/FilterBarComboBox.cc | 147 +++ qt/FilterBarComboBox.h | 41 + qt/FilterBarComboBoxDelegate.cc | 121 ++ qt/FilterBarComboBoxDelegate.h | 37 + qt/FilterBarLineEdit.cc | 73 ++ qt/FilterBarLineEdit.h | 34 + qt/{filters.cc => Filters.cc} | 4 +- qt/{filters.h => Filters.h} | 4 +- qt/{formatter.cc => Formatter.cc} | 6 +- qt/{formatter.h => Formatter.h} | 12 +- qt/{freespace-label.cc => FreeSpaceLabel.cc} | 18 +- qt/{freespace-label.h => FreeSpaceLabel.h} | 15 +- qt/{tricontoolbutton.cc => IconToolButton.cc} | 8 +- qt/{tricontoolbutton.h => IconToolButton.h} | 6 +- qt/{license.cc => LicenseDialog.cc} | 4 +- qt/{license.h => LicenseDialog.h} | 9 +- qt/{mainwin.cc => MainWindow.cc} | 207 ++-- qt/{mainwin.h => MainWindow.h} | 34 +- qt/{mainwin.ui => MainWindow.ui} | 8 +- qt/{make-dialog.cc => MakeDialog.cc} | 22 +- qt/{make-dialog.h => MakeDialog.h} | 10 +- qt/{make-dialog.ui => MakeDialog.ui} | 10 +- ...ogress-dialog.ui => MakeProgressDialog.ui} | 0 qt/{options.cc => OptionsDialog.cc} | 29 +- qt/{options.h => OptionsDialog.h} | 14 +- qt/{options.ui => OptionsDialog.ui} | 16 +- qt/{path-button.cc => PathButton.cc} | 32 +- qt/{path-button.h => PathButton.h} | 6 +- qt/{prefs.cc => Prefs.cc} | 24 +- qt/{prefs.h => Prefs.h} | 8 +- qt/{prefs-dialog.cc => PrefsDialog.cc} | 31 +- qt/{prefs-dialog.h => PrefsDialog.h} | 14 +- qt/{prefs-dialog.ui => PrefsDialog.ui} | 18 +- qt/{relocate.cc => RelocateDialog.cc} | 12 +- qt/{relocate.h => RelocateDialog.h} | 10 +- qt/{relocate.ui => RelocateDialog.ui} | 6 +- qt/{rpc-client.cc => RpcClient.cc} | 4 +- qt/{rpc-client.h => RpcClient.h} | 8 +- qt/{session.cc => Session.cc} | 18 +- qt/{session.h => Session.h} | 10 +- qt/{session-dialog.cc => SessionDialog.cc} | 8 +- qt/{session-dialog.h => SessionDialog.h} | 10 +- qt/{session-dialog.ui => SessionDialog.ui} | 0 qt/{speed.h => Speed.h} | 6 +- qt/{squeezelabel.cc => SqueezeLabel.cc} | 2 +- qt/{squeezelabel.h => SqueezeLabel.h} | 9 +- qt/{stats-dialog.cc => StatsDialog.cc} | 10 +- qt/{stats-dialog.h => StatsDialog.h} | 10 +- qt/{stats-dialog.ui => StatsDialog.ui} | 0 qt/{torrent.cc => Torrent.cc} | 25 +- qt/{torrent.h => Torrent.h} | 25 +- ...torrent-delegate.cc => TorrentDelegate.cc} | 12 +- qt/{torrent-delegate.h => TorrentDelegate.h} | 4 +- ...-delegate-min.cc => TorrentDelegateMin.cc} | 10 +- ...nt-delegate-min.h => TorrentDelegateMin.h} | 7 +- qt/{torrent-filter.cc => TorrentFilter.cc} | 15 +- qt/{torrent-filter.h => TorrentFilter.h} | 4 +- qt/{torrent-model.cc => TorrentModel.cc} | 6 +- qt/{torrent-model.h => TorrentModel.h} | 8 +- ...tracker-delegate.cc => TrackerDelegate.cc} | 16 +- qt/{tracker-delegate.h => TrackerDelegate.h} | 5 +- qt/{tracker-model.cc => TrackerModel.cc} | 6 +- qt/{tracker-model.h => TrackerModel.h} | 8 +- ...-model-filter.cc => TrackerModelFilter.cc} | 6 +- ...er-model-filter.h => TrackerModelFilter.h} | 4 +- qt/{utils.cc => Utils.cc} | 13 +- qt/{utils.h => Utils.h} | 16 +- qt/{watchdir.cc => WatchDir.cc} | 8 +- qt/{watchdir.h => WatchDir.h} | 11 +- qt/file-tree.cc | 1025 ----------------- qt/file-tree.h | 193 ---- qt/filterbar.cc | 728 ------------ qt/hig.cc | 240 ---- qt/hig.h | 72 -- qt/qtr.pro | 100 +- 103 files changed, 2914 insertions(+), 3061 deletions(-) rename qt/{about.cc => AboutDialog.cc} (92%) rename qt/{about.h => AboutDialog.h} (70%) rename qt/{about.ui => AboutDialog.ui} (100%) rename qt/{add-data.cc => AddData.cc} (96%) rename qt/{add-data.h => AddData.h} (84%) rename qt/{app.cc => Application.cc} (94%) rename qt/{app.h => Application.h} (74%) rename qt/{column-resizer.cc => ColumnResizer.cc} (98%) rename qt/{column-resizer.h => ColumnResizer.h} (95%) rename qt/{types.h => CustomVariantType.h} (79%) rename qt/{dbus-adaptor.cc => DBusAdaptor.cc} (57%) rename qt/{dbus-adaptor.h => DBusAdaptor.h} (63%) rename qt/{details.cc => DetailsDialog.cc} (95%) rename qt/{details.h => DetailsDialog.h} (86%) rename qt/{details.ui => DetailsDialog.ui} (99%) rename qt/{favicon.cc => FaviconCache.cc} (87%) rename qt/{favicon.h => FaviconCache.h} (82%) create mode 100644 qt/FileTreeDelegate.cc create mode 100644 qt/FileTreeDelegate.h create mode 100644 qt/FileTreeItem.cc create mode 100644 qt/FileTreeItem.h create mode 100644 qt/FileTreeModel.cc create mode 100644 qt/FileTreeModel.h create mode 100644 qt/FileTreeView.cc create mode 100644 qt/FileTreeView.h create mode 100644 qt/FilterBar.cc rename qt/{filterbar.h => FilterBar.h} (51%) create mode 100644 qt/FilterBarComboBox.cc create mode 100644 qt/FilterBarComboBox.h create mode 100644 qt/FilterBarComboBoxDelegate.cc create mode 100644 qt/FilterBarComboBoxDelegate.h create mode 100644 qt/FilterBarLineEdit.cc create mode 100644 qt/FilterBarLineEdit.h rename qt/{filters.cc => Filters.cc} (94%) rename qt/{filters.h => Filters.h} (95%) rename qt/{formatter.cc => Formatter.cc} (97%) rename qt/{formatter.h => Formatter.h} (89%) rename qt/{freespace-label.cc => FreeSpaceLabel.cc} (83%) rename qt/{freespace-label.h => FreeSpaceLabel.h} (69%) rename qt/{tricontoolbutton.cc => IconToolButton.cc} (69%) rename qt/{tricontoolbutton.h => IconToolButton.h} (70%) rename qt/{license.cc => LicenseDialog.cc} (95%) rename qt/{license.h => LicenseDialog.h} (66%) rename qt/{mainwin.cc => MainWindow.cc} (90%) rename qt/{mainwin.h => MainWindow.h} (91%) rename qt/{mainwin.ui => MainWindow.ui} (99%) rename qt/{make-dialog.cc => MakeDialog.cc} (94%) rename qt/{make-dialog.h => MakeDialog.h} (82%) rename qt/{make-dialog.ui => MakeDialog.ui} (96%) rename qt/{make-progress-dialog.ui => MakeProgressDialog.ui} (100%) rename qt/{options.cc => OptionsDialog.cc} (96%) rename qt/{options.h => OptionsDialog.h} (86%) rename qt/{options.ui => OptionsDialog.ui} (91%) rename qt/{path-button.cc => PathButton.cc} (85%) rename qt/{path-button.h => PathButton.h} (88%) rename qt/{prefs.cc => Prefs.cc} (96%) rename qt/{prefs.h => Prefs.h} (97%) rename qt/{prefs-dialog.cc => PrefsDialog.cc} (96%) rename qt/{prefs-dialog.h => PrefsDialog.h} (91%) rename qt/{prefs-dialog.ui => PrefsDialog.ui} (98%) rename qt/{relocate.cc => RelocateDialog.cc} (91%) rename qt/{relocate.h => RelocateDialog.h} (78%) rename qt/{relocate.ui => RelocateDialog.ui} (94%) rename qt/{rpc-client.cc => RpcClient.cc} (98%) rename qt/{rpc-client.h => RpcClient.h} (92%) rename qt/{session.cc => Session.cc} (98%) rename qt/{session.h => Session.h} (97%) rename qt/{session-dialog.cc => SessionDialog.cc} (95%) rename qt/{session-dialog.h => SessionDialog.h} (77%) rename qt/{session-dialog.ui => SessionDialog.ui} (100%) rename qt/{speed.h => Speed.h} (88%) rename qt/{squeezelabel.cc => SqueezeLabel.cc} (99%) rename qt/{squeezelabel.h => SqueezeLabel.h} (94%) rename qt/{stats-dialog.cc => StatsDialog.cc} (92%) rename qt/{stats-dialog.h => StatsDialog.h} (74%) rename qt/{stats-dialog.ui => StatsDialog.ui} (100%) rename qt/{torrent.cc => Torrent.cc} (97%) rename qt/{torrent.h => Torrent.h} (97%) rename qt/{torrent-delegate.cc => TorrentDelegate.cc} (99%) rename qt/{torrent-delegate.h => TorrentDelegate.h} (94%) rename qt/{torrent-delegate-min.cc => TorrentDelegateMin.cc} (98%) rename qt/{torrent-delegate-min.h => TorrentDelegateMin.h} (85%) rename qt/{torrent-filter.cc => TorrentFilter.cc} (96%) rename qt/{torrent-filter.h => TorrentFilter.h} (93%) rename qt/{torrent-model.cc => TorrentModel.cc} (98%) rename qt/{torrent-model.h => TorrentModel.h} (93%) rename qt/{tracker-delegate.cc => TrackerDelegate.cc} (97%) rename qt/{tracker-delegate.h => TrackerDelegate.h} (92%) rename qt/{tracker-model.cc => TrackerModel.cc} (97%) rename qt/{tracker-model.h => TrackerModel.h} (87%) rename qt/{tracker-model-filter.cc => TrackerModelFilter.cc} (86%) rename qt/{tracker-model-filter.h => TrackerModelFilter.h} (87%) rename qt/{utils.cc => Utils.cc} (96%) rename qt/{utils.h => Utils.h} (87%) rename qt/{watchdir.cc => WatchDir.cc} (96%) rename qt/{watchdir.h => WatchDir.h} (86%) delete mode 100644 qt/file-tree.cc delete mode 100644 qt/file-tree.h delete mode 100644 qt/filterbar.cc delete mode 100644 qt/hig.cc delete mode 100644 qt/hig.h diff --git a/qt/about.cc b/qt/AboutDialog.cc similarity index 92% rename from qt/about.cc rename to qt/AboutDialog.cc index 3ca7ed868..a6265777b 100644 --- a/qt/about.cc +++ b/qt/AboutDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -15,8 +15,8 @@ #include #include -#include "about.h" -#include "license.h" +#include "AboutDialog.h" +#include "LicenseDialog.h" AboutDialog::AboutDialog (QWidget * parent): QDialog (parent, Qt::Dialog), diff --git a/qt/about.h b/qt/AboutDialog.h similarity index 70% rename from qt/about.h rename to qt/AboutDialog.h index 3a914a902..453a9e1b0 100644 --- a/qt/about.h +++ b/qt/AboutDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,12 +7,12 @@ * $Id$ */ -#ifndef ABOUT_DIALOG_H -#define ABOUT_DIALOG_H +#ifndef QTR_ABOUT_DIALOG_H +#define QTR_ABOUT_DIALOG_H #include -#include "ui_about.h" +#include "ui_AboutDialog.h" class AboutDialog: public QDialog { @@ -30,4 +30,4 @@ class AboutDialog: public QDialog Ui::AboutDialog ui; }; -#endif +#endif // QTR_ABOUT_DIALOG_H diff --git a/qt/about.ui b/qt/AboutDialog.ui similarity index 100% rename from qt/about.ui rename to qt/AboutDialog.ui diff --git a/qt/add-data.cc b/qt/AddData.cc similarity index 96% rename from qt/add-data.cc rename to qt/AddData.cc index fffc37261..d1edfc0bd 100644 --- a/qt/add-data.cc +++ b/qt/AddData.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -13,8 +13,8 @@ #include #include // tr_base64_encode() -#include "add-data.h" -#include "utils.h" +#include "AddData.h" +#include "Utils.h" int AddData::set (const QString& key) diff --git a/qt/add-data.h b/qt/AddData.h similarity index 84% rename from qt/add-data.h rename to qt/AddData.h index eda1eaee0..1dcc60bfb 100644 --- a/qt/add-data.h +++ b/qt/AddData.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef ADD_DATA_H -#define ADD_DATA_H +#ifndef QTR_ADD_DATA_H +#define QTR_ADD_DATA_H #include #include @@ -40,4 +40,4 @@ class AddData static bool isSupported (const QString& str) { return AddData(str).type != NONE; } }; -#endif +#endif // QTR_ADD_DATA_H diff --git a/qt/app.cc b/qt/Application.cc similarity index 94% rename from qt/app.cc rename to qt/Application.cc index 810f3fcc7..53aa76969 100644 --- a/qt/app.cc +++ b/qt/Application.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -26,17 +26,17 @@ #include #include -#include "add-data.h" -#include "app.h" -#include "dbus-adaptor.h" -#include "formatter.h" -#include "mainwin.h" -#include "options.h" -#include "prefs.h" -#include "session.h" -#include "session-dialog.h" -#include "torrent-model.h" -#include "watchdir.h" +#include "AddData.h" +#include "Application.h" +#include "DBusAdaptor.h" +#include "Formatter.h" +#include "MainWindow.h" +#include "OptionsDialog.h" +#include "Prefs.h" +#include "Session.h" +#include "SessionDialog.h" +#include "TorrentModel.h" +#include "WatchDir.h" namespace { @@ -87,7 +87,7 @@ namespace } } -MyApp::MyApp (int& argc, char ** argv): +Application::Application (int& argc, char ** argv): QApplication (argc, argv), myPrefs(nullptr), mySession(nullptr), @@ -245,7 +245,7 @@ MyApp::MyApp (int& argc, char ** argv): mySession = new Session (configDir, *myPrefs); myModel = new TorrentModel (*myPrefs); - myWindow = new TrMainWindow (*mySession, *myPrefs, *myModel, minimized); + myWindow = new MainWindow (*mySession, *myPrefs, *myModel, minimized); myWatchDir = new WatchDir (*myModel); // when the session gets torrent info, update the model @@ -324,7 +324,7 @@ MyApp::MyApp (int& argc, char ** argv): // register as the dbus handler for Transmission if (bus.isConnected ()) { - new TrDBusAdaptor (this); + new DBusAdaptor (this); if (!bus.registerService (DBUS_SERVICE)) std::cerr << "couldn't register " << qPrintable (DBUS_SERVICE) << std::endl; if (!bus.registerObject (DBUS_OBJECT_PATH, this)) @@ -333,7 +333,7 @@ MyApp::MyApp (int& argc, char ** argv): } void -MyApp::quitLater () +Application::quitLater () { QTimer::singleShot (0, this, SLOT (quit ())); } @@ -341,7 +341,7 @@ MyApp::quitLater () /* these functions are for popping up desktop notifications */ void -MyApp::onTorrentsAdded (const QSet& torrents) +Application::onTorrentsAdded (const QSet& torrents) { if (!myPrefs->getBool (Prefs::SHOW_NOTIFICATION_ON_ADD)) return; @@ -365,7 +365,7 @@ MyApp::onTorrentsAdded (const QSet& torrents) } void -MyApp::onTorrentCompleted (int id) +Application::onTorrentCompleted (int id) { Torrent * tor = myModel->getTorrentFromId (id); @@ -388,7 +388,7 @@ MyApp::onTorrentCompleted (int id) } void -MyApp::onNewTorrentChanged (int id) +Application::onNewTorrentChanged (int id) { Torrent * tor = myModel->getTorrentFromId (id); @@ -410,7 +410,7 @@ MyApp::onNewTorrentChanged (int id) ***/ void -MyApp::consentGiven (int result) +Application::consentGiven (int result) { if (result == QMessageBox::Ok) myPrefs->set (Prefs::USER_HAS_GIVEN_INFORMED_CONSENT, true); @@ -418,7 +418,7 @@ MyApp::consentGiven (int result) quit (); } -MyApp::~MyApp () +Application::~Application () { if (myPrefs != nullptr && myWindow != nullptr) { @@ -441,7 +441,7 @@ MyApp::~MyApp () ***/ void -MyApp::refreshPref (int key) +Application::refreshPref (int key) { switch (key) { @@ -464,7 +464,7 @@ MyApp::refreshPref (int key) } void -MyApp::maybeUpdateBlocklist () +Application::maybeUpdateBlocklist () { if (!myPrefs->getBool (Prefs::BLOCKLIST_UPDATES_ENABLED)) return; @@ -481,7 +481,7 @@ MyApp::maybeUpdateBlocklist () } void -MyApp::onSessionSourceChanged () +Application::onSessionSourceChanged () { mySession->initTorrents (); mySession->refreshSessionStats (); @@ -489,7 +489,7 @@ MyApp::onSessionSourceChanged () } void -MyApp::refreshTorrents () +Application::refreshTorrents () { // usually we just poll the torrents that have shown recent activity, // but we also periodically ask for updates on the others to ensure @@ -511,7 +511,7 @@ MyApp::refreshTorrents () ***/ void -MyApp::addTorrent (const QString& key) +Application::addTorrent (const QString& key) { const AddData addme (key); @@ -520,7 +520,7 @@ MyApp::addTorrent (const QString& key) } void -MyApp::addTorrent (const AddData& addme) +Application::addTorrent (const AddData& addme) { if (!myPrefs->getBool (Prefs::OPTIONS_PROMPT)) { @@ -540,13 +540,13 @@ MyApp::addTorrent (const AddData& addme) ***/ void -MyApp::raise () +Application::raise () { alert (myWindow); } bool -MyApp::notifyApp (const QString& title, const QString& body) const +Application::notifyApp (const QString& title, const QString& body) const { const QString dbusServiceName = QString::fromUtf8 ("org.freedesktop.Notifications"); const QString dbusInterfaceName = QString::fromUtf8 ("org.freedesktop.Notifications"); @@ -577,6 +577,6 @@ int tr_main (int argc, char * argv[]) { - MyApp app (argc, argv); + Application app (argc, argv); return app.exec (); } diff --git a/qt/app.h b/qt/Application.h similarity index 74% rename from qt/app.h rename to qt/Application.h index eda5f35c3..40268153a 100644 --- a/qt/app.h +++ b/qt/Application.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,43 +7,43 @@ * $Id$ */ -#ifndef QTR_APP_H -#define QTR_APP_H +#ifndef QTR_APPLICATION_H +#define QTR_APPLICATION_H #include #include #include #include -#include "favicon.h" +#include "FaviconCache.h" class AddData; class Prefs; class Session; class TorrentModel; -class TrMainWindow; +class MainWindow; class WatchDir; -class MyApp: public QApplication +class Application: public QApplication { Q_OBJECT public: - MyApp (int& argc, char ** argv); - virtual ~MyApp (); + Application (int& argc, char ** argv); + virtual ~Application (); public: void raise (); bool notifyApp (const QString& title, const QString& body) const; public: - Favicons favicons; + FaviconCache favicons; private: Prefs * myPrefs; Session * mySession; TorrentModel * myModel; - TrMainWindow * myWindow; + MainWindow * myWindow; WatchDir * myWatchDir; QTimer myModelTimer; QTimer myStatsTimer; @@ -72,6 +72,6 @@ class MyApp: public QApplication }; #undef qApp -#define qApp static_cast (MyApp::instance ()) +#define qApp static_cast (Application::instance ()) -#endif +#endif // QTR_APPLICATION_H diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 5c8ae8df2..485efce3c 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -25,98 +25,108 @@ else() endif() set(${PROJECT_NAME}_SOURCES - about.cc - add-data.cc - app.cc - column-resizer.cc - dbus-adaptor.cc - details.cc - favicon.cc - file-tree.cc - filterbar.cc - filters.cc - formatter.cc - freespace-label.cc - hig.cc - license.cc - mainwin.cc - make-dialog.cc - options.cc - path-button.cc - prefs-dialog.cc - prefs.cc - relocate.cc - rpc-client.cc - session-dialog.cc - session.cc - squeezelabel.cc - stats-dialog.cc - torrent-delegate-min.cc - torrent-delegate.cc - torrent-filter.cc - torrent-model.cc - torrent.cc - tracker-delegate.cc - tracker-model-filter.cc - tracker-model.cc - tricontoolbutton.cc - utils.cc - watchdir.cc + AboutDialog.cc + AddData.cc + Application.cc + ColumnResizer.cc + DBusAdaptor.cc + DetailsDialog.cc + FaviconCache.cc + FileTreeDelegate.cc + FileTreeItem.cc + FileTreeModel.cc + FileTreeView.cc + FilterBar.cc + FilterBarComboBox.cc + FilterBarComboBoxDelegate.cc + FilterBarLineEdit.cc + Filters.cc + Formatter.cc + FreeSpaceLabel.cc + IconToolButton.cc + LicenseDialog.cc + MainWindow.cc + MakeDialog.cc + OptionsDialog.cc + PathButton.cc + Prefs.cc + PrefsDialog.cc + RelocateDialog.cc + RpcClient.cc + Session.cc + SessionDialog.cc + SqueezeLabel.cc + StatsDialog.cc + Torrent.cc + TorrentDelegate.cc + TorrentDelegateMin.cc + TorrentFilter.cc + TorrentModel.cc + TrackerDelegate.cc + TrackerModel.cc + TrackerModelFilter.cc + Utils.cc + WatchDir.cc ) set(${PROJECT_NAME}_HEADERS - about.h - add-data.h - app.h - column-resizer.h - dbus-adaptor.h - details.h - favicon.h - file-tree.h - filterbar.h - filters.h - formatter.h - freespace-label.h - hig.h - license.h - mainwin.h - make-dialog.h - options.h - path-button.h - prefs-dialog.h - prefs.h - relocate.h - rpc-client.h - session-dialog.h - session.h - speed.h - squeezelabel.h - stats-dialog.h - torrent-delegate-min.h - torrent-delegate.h - torrent-filter.h - torrent-model.h - torrent.h - tracker-delegate.h - tracker-model-filter.h - tracker-model.h - tricontoolbutton.h - types.h - utils.h - watchdir.h + AboutDialog.h + AddData.h + Application.h + ColumnResizer.h + CustomVariantType.h + DBusAdaptor.h + DetailsDialog.h + FaviconCache.h + FileTreeDelegate.h + FileTreeItem.h + FileTreeModel.h + FileTreeView.h + FilterBar.h + FilterBarComboBox.h + FilterBarComboBoxDelegate.h + FilterBarLineEdit.h + Filters.h + Formatter.h + FreeSpaceLabel.h + IconToolButton.h + LicenseDialog.h + MainWindow.h + MakeDialog.h + OptionsDialog.h + PathButton.h + Prefs.h + PrefsDialog.h + RelocateDialog.h + RpcClient.h + Session.h + SessionDialog.h + Speed.h + SqueezeLabel.h + StatsDialog.h + Torrent.h + TorrentDelegate.h + TorrentDelegateMin.h + TorrentFilter.h + TorrentModel.h + TrackerDelegate.h + TrackerModel.h + TrackerModelFilter.h + Utils.h + WatchDir.h ) tr_qt_wrap_ui(${PROJECT_NAME}_UI_SOURCES - about.ui - details.ui - mainwin.ui - make-dialog.ui - make-progress-dialog.ui - options.ui - prefs-dialog.ui - relocate.ui - session-dialog.ui - stats-dialog.ui + AboutDialog.ui + DetailsDialog.ui + MainWindow.ui + MakeDialog.ui + MakeProgressDialog.ui + OptionsDialog.ui + PrefsDialog.ui + RelocateDialog.ui + SessionDialog.ui + StatsDialog.ui ) set(${PROJECT_NAME}_QRC_FILES application.qrc) diff --git a/qt/column-resizer.cc b/qt/ColumnResizer.cc similarity index 98% rename from qt/column-resizer.cc rename to qt/ColumnResizer.cc index dc4671c2a..bb8911a3d 100644 --- a/qt/column-resizer.cc +++ b/qt/ColumnResizer.cc @@ -11,7 +11,7 @@ #include #include -#include "column-resizer.h" +#include "ColumnResizer.h" namespace { diff --git a/qt/column-resizer.h b/qt/ColumnResizer.h similarity index 95% rename from qt/column-resizer.h rename to qt/ColumnResizer.h index 24eba3c5f..d84041648 100644 --- a/qt/column-resizer.h +++ b/qt/ColumnResizer.h @@ -38,4 +38,4 @@ class ColumnResizer: public QObject QSet myLayouts; }; -#endif +#endif // QTR_COLUMN_RESIZER_H diff --git a/qt/types.h b/qt/CustomVariantType.h similarity index 79% rename from qt/types.h rename to qt/CustomVariantType.h index 17cccf662..b70f15288 100644 --- a/qt/types.h +++ b/qt/CustomVariantType.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -12,7 +12,7 @@ #include -class TrTypes +class CustomVariantType { public: @@ -26,4 +26,4 @@ class TrTypes }; }; -#endif +#endif // QTR_TYPES_H diff --git a/qt/dbus-adaptor.cc b/qt/DBusAdaptor.cc similarity index 57% rename from qt/dbus-adaptor.cc rename to qt/DBusAdaptor.cc index 0078a9f49..6e41cd83e 100644 --- a/qt/dbus-adaptor.cc +++ b/qt/DBusAdaptor.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,25 +7,25 @@ * $Id$ */ -#include "add-data.h" -#include "app.h" -#include "dbus-adaptor.h" +#include "AddData.h" +#include "Application.h" +#include "DBusAdaptor.h" -TrDBusAdaptor::TrDBusAdaptor (MyApp* app): +DBusAdaptor::DBusAdaptor (Application* app): QDBusAbstractAdaptor (app), myApp (app) { } bool -TrDBusAdaptor::PresentWindow () +DBusAdaptor::PresentWindow () { myApp->raise (); return true; } bool -TrDBusAdaptor::AddMetainfo (const QString& key) +DBusAdaptor::AddMetainfo (const QString& key) { AddData addme (key); diff --git a/qt/dbus-adaptor.h b/qt/DBusAdaptor.h similarity index 63% rename from qt/dbus-adaptor.h rename to qt/DBusAdaptor.h index 9d9f53a48..dfdab9ed9 100644 --- a/qt/dbus-adaptor.h +++ b/qt/DBusAdaptor.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -10,25 +10,25 @@ #ifndef QTR_DBUS_ADAPTOR_H #define QTR_DBUS_ADAPTOR_H -class MyApp; - #include -class TrDBusAdaptor: public QDBusAbstractAdaptor +class Application; + +class DBusAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO( "D-Bus Interface", "com.transmissionbt.Transmission" ) private: - MyApp * myApp; + Application * myApp; public: - TrDBusAdaptor( MyApp* ); - virtual ~TrDBusAdaptor() {} + DBusAdaptor( Application* ); + virtual ~DBusAdaptor() {} public slots: bool PresentWindow(); bool AddMetainfo( const QString& ); }; -#endif +#endif // QTR_DBUS_ADAPTOR_H diff --git a/qt/details.cc b/qt/DetailsDialog.cc similarity index 95% rename from qt/details.cc rename to qt/DetailsDialog.cc index 25daa3471..d070fa5fe 100644 --- a/qt/details.cc +++ b/qt/DetailsDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -32,20 +32,18 @@ #include #include // tr_getRatio () -#include "column-resizer.h" -#include "details.h" -#include "file-tree.h" -#include "formatter.h" -#include "hig.h" -#include "prefs.h" -#include "session.h" -#include "squeezelabel.h" -#include "torrent.h" -#include "torrent-model.h" -#include "tracker-delegate.h" -#include "tracker-model.h" -#include "tracker-model-filter.h" -#include "utils.h" +#include "ColumnResizer.h" +#include "DetailsDialog.h" +#include "Formatter.h" +#include "Prefs.h" +#include "Session.h" +#include "SqueezeLabel.h" +#include "Torrent.h" +#include "TorrentModel.h" +#include "TrackerDelegate.h" +#include "TrackerModel.h" +#include "TrackerModelFilter.h" +#include "Utils.h" class Prefs; class Session; @@ -164,7 +162,7 @@ class PeerItem: public QTreeWidgetItem ***/ QIcon -Details::getStockIcon (const QString& freedesktop_name, int fallback) +DetailsDialog::getStockIcon (const QString& freedesktop_name, int fallback) { QIcon icon = QIcon::fromTheme (freedesktop_name); @@ -174,7 +172,7 @@ Details::getStockIcon (const QString& freedesktop_name, int fallback) return icon; } -Details::Details (Session & session, +DetailsDialog::DetailsDialog (Session & session, Prefs & prefs, const TorrentModel& model, QWidget * parent): @@ -212,7 +210,7 @@ Details::Details (Session & session, myTimer.start (REFRESH_INTERVAL_MSEC); } -Details::~Details () +DetailsDialog::~DetailsDialog () { myTrackerDelegate->deleteLater (); myTrackerFilter->deleteLater (); @@ -220,7 +218,7 @@ Details::~Details () } void -Details::setIds (const QSet& ids) +DetailsDialog::setIds (const QSet& ids) { if (ids == myIds) return; @@ -254,7 +252,7 @@ Details::setIds (const QSet& ids) } void -Details::refreshPref (int key) +DetailsDialog::refreshPref (int key) { QString str; @@ -288,7 +286,7 @@ Details::refreshPref (int key) ***/ QString -Details::timeToStringRounded (int seconds) +DetailsDialog::timeToStringRounded (int seconds) { if (seconds > 60) seconds -= (seconds % 60); @@ -297,13 +295,13 @@ Details::timeToStringRounded (int seconds) } void -Details::onTimer () +DetailsDialog::onTimer () { getNewData (); } void -Details::getNewData () +DetailsDialog::getNewData () { if (!myIds.empty ()) { @@ -322,7 +320,7 @@ Details::getNewData () } void -Details::onTorrentChanged () +DetailsDialog::onTorrentChanged () { if (!myHavePendingRefresh) { @@ -365,7 +363,7 @@ namespace } void -Details::refresh () +DetailsDialog::refresh () { const int n = myIds.size (); const bool single = n == 1; @@ -961,7 +959,7 @@ Details::refresh () ***/ void -Details::initInfoTab () +DetailsDialog::initInfoTab () { const int h = QFontMetrics (ui.commentBrowser->font ()).lineSpacing () * 4; ui.commentBrowser->setFixedHeight (h); @@ -977,31 +975,31 @@ Details::initInfoTab () ***/ void -Details::onShowTrackerScrapesToggled (bool val) +DetailsDialog::onShowTrackerScrapesToggled (bool val) { myPrefs.set (Prefs::SHOW_TRACKER_SCRAPES, val); } void -Details::onShowBackupTrackersToggled (bool val) +DetailsDialog::onShowBackupTrackersToggled (bool val) { myPrefs.set (Prefs::SHOW_BACKUP_TRACKERS, val); } void -Details::onHonorsSessionLimitsToggled (bool val) +DetailsDialog::onHonorsSessionLimitsToggled (bool val) { mySession.torrentSet (myIds, TR_KEY_honorsSessionLimits, val); getNewData (); } void -Details::onDownloadLimitedToggled (bool val) +DetailsDialog::onDownloadLimitedToggled (bool val) { mySession.torrentSet (myIds, TR_KEY_downloadLimited, val); getNewData (); } void -Details::onSpinBoxEditingFinished () +DetailsDialog::onSpinBoxEditingFinished () { const QObject * spin = sender (); const tr_quark key = spin->property (PREF_KEY).toInt (); @@ -1014,14 +1012,14 @@ Details::onSpinBoxEditingFinished () } void -Details::onUploadLimitedToggled (bool val) +DetailsDialog::onUploadLimitedToggled (bool val) { mySession.torrentSet (myIds, TR_KEY_uploadLimited, val); getNewData (); } void -Details::onIdleModeChanged (int index) +DetailsDialog::onIdleModeChanged (int index) { const int val = ui.idleCombo->itemData (index).toInt (); mySession.torrentSet (myIds, TR_KEY_seedIdleMode, val); @@ -1029,7 +1027,7 @@ Details::onIdleModeChanged (int index) } void -Details::onIdleLimitChanged () +DetailsDialog::onIdleLimitChanged () { //: Spin box suffix, "Stop seeding if idle for: [ 5 minutes ]" (includes leading space after the number, if needed) const QString unitsSuffix = tr (" minute(s)", 0, ui.idleSpin->value ()); @@ -1038,14 +1036,14 @@ Details::onIdleLimitChanged () } void -Details::onRatioModeChanged (int index) +DetailsDialog::onRatioModeChanged (int index) { const int val = ui.ratioCombo->itemData (index).toInt (); mySession.torrentSet (myIds, TR_KEY_seedRatioMode, val); } void -Details::onBandwidthPriorityChanged (int index) +DetailsDialog::onBandwidthPriorityChanged (int index) { if (index != -1) { @@ -1056,7 +1054,7 @@ Details::onBandwidthPriorityChanged (int index) } void -Details::onTrackerSelectionChanged () +DetailsDialog::onTrackerSelectionChanged () { const int selectionCount = ui.trackersView->selectionModel ()->selectedRows ().size (); ui.editTrackerButton->setEnabled (selectionCount == 1); @@ -1064,7 +1062,7 @@ Details::onTrackerSelectionChanged () } void -Details::onAddTrackerClicked () +DetailsDialog::onAddTrackerClicked () { bool ok = false; const QString url = QInputDialog::getText (this, @@ -1102,7 +1100,7 @@ Details::onAddTrackerClicked () } void -Details::onEditTrackerClicked () +DetailsDialog::onEditTrackerClicked () { QItemSelectionModel * selectionModel = ui.trackersView->selectionModel (); QModelIndexList selectedRows = selectionModel->selectedRows (); @@ -1138,7 +1136,7 @@ Details::onEditTrackerClicked () } void -Details::onRemoveTrackerClicked () +DetailsDialog::onRemoveTrackerClicked () { // make a map of torrentIds to announce URLs to remove QItemSelectionModel * selectionModel = ui.trackersView->selectionModel (); @@ -1163,7 +1161,7 @@ Details::onRemoveTrackerClicked () } void -Details::initOptionsTab () +DetailsDialog::initOptionsTab () { const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB); @@ -1214,7 +1212,7 @@ Details::initOptionsTab () ***/ void -Details::initTrackerTab () +DetailsDialog::initTrackerTab () { myTrackerModel = new TrackerModel (); myTrackerFilter = new TrackerModelFilter (); @@ -1247,7 +1245,7 @@ Details::initTrackerTab () ***/ void -Details::initPeersTab () +DetailsDialog::initPeersTab () { QStringList headers; headers << QString () << tr ("Up") << tr ("Down") << tr ("%") << tr ("Status") << tr ("Address") << tr ("Client"); @@ -1268,7 +1266,7 @@ Details::initPeersTab () ***/ void -Details::initFilesTab () +DetailsDialog::initFilesTab () { connect (ui.filesView, SIGNAL (priorityChanged (QSet, int)), SLOT (onFilePriorityChanged (QSet, int))); connect (ui.filesView, SIGNAL (wantedChanged (QSet, bool)), SLOT (onFileWantedChanged (QSet, bool))); @@ -1277,7 +1275,7 @@ Details::initFilesTab () } void -Details::onFilePriorityChanged (const QSet& indices, int priority) +DetailsDialog::onFilePriorityChanged (const QSet& indices, int priority) { tr_quark key; @@ -1301,7 +1299,7 @@ Details::onFilePriorityChanged (const QSet& indices, int priority) } void -Details::onFileWantedChanged (const QSet& indices, bool wanted) +DetailsDialog::onFileWantedChanged (const QSet& indices, bool wanted) { const tr_quark key = wanted ? TR_KEY_files_wanted : TR_KEY_files_unwanted; mySession.torrentSet (myIds, key, indices.toList ()); @@ -1309,13 +1307,13 @@ Details::onFileWantedChanged (const QSet& indices, bool wanted) } void -Details::onPathEdited (const QString& oldpath, const QString& newname) +DetailsDialog::onPathEdited (const QString& oldpath, const QString& newname) { mySession.torrentRenamePath (myIds, oldpath, newname); } void -Details::onOpenRequested (const QString& path) +DetailsDialog::onOpenRequested (const QString& path) { if (!mySession.isLocal ()) return; diff --git a/qt/details.h b/qt/DetailsDialog.h similarity index 86% rename from qt/details.h rename to qt/DetailsDialog.h index fb304e23a..8d0f60a3b 100644 --- a/qt/details.h +++ b/qt/DetailsDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef DETAILS_DIALOG_H -#define DETAILS_DIALOG_H +#ifndef QTR_DETAILS_DIALOG_H +#define QTR_DETAILS_DIALOG_H #include #include @@ -16,9 +16,9 @@ #include #include -#include "prefs.h" +#include "Prefs.h" -#include "ui_details.h" +#include "ui_DetailsDialog.h" class QTreeWidgetItem; class Session; @@ -28,7 +28,7 @@ class TrackerDelegate; class TrackerModel; class TrackerModelFilter; -class Details: public QDialog +class DetailsDialog: public QDialog { Q_OBJECT @@ -40,8 +40,8 @@ class Details: public QDialog void onTimer (); public: - Details (Session&, Prefs&, const TorrentModel&, QWidget * parent = 0); - ~Details (); + DetailsDialog (Session&, Prefs&, const TorrentModel&, QWidget * parent = 0); + ~DetailsDialog (); void setIds (const QSet& ids); virtual QSize sizeHint () const { return QSize (440, 460); } @@ -97,4 +97,4 @@ class Details: public QDialog void refresh (); }; -#endif +#endif // QTR_DETAILS_DIALOG_H diff --git a/qt/details.ui b/qt/DetailsDialog.ui similarity index 99% rename from qt/details.ui rename to qt/DetailsDialog.ui index 2b20a1b75..f0cb90641 100644 --- a/qt/details.ui +++ b/qt/DetailsDialog.ui @@ -852,12 +852,12 @@ SqueezeLabel QLabel -
squeezelabel.h
+
SqueezeLabel.h
FileTreeView QTreeView -
file-tree.h
+
FileTreeView.h
diff --git a/qt/favicon.cc b/qt/FaviconCache.cc similarity index 87% rename from qt/favicon.cc rename to qt/FaviconCache.cc index 30a3771b2..dc8eaa9b8 100644 --- a/qt/favicon.cc +++ b/qt/FaviconCache.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -18,19 +18,19 @@ #include #endif -#include "favicon.h" +#include "FaviconCache.h" /*** **** ***/ -Favicons::Favicons () +FaviconCache::FaviconCache () { myNAM = new QNetworkAccessManager (); connect (myNAM, SIGNAL(finished(QNetworkReply*)), this, SLOT(onRequestFinished(QNetworkReply*))); } -Favicons::~Favicons () +FaviconCache::~FaviconCache () { delete myNAM; } @@ -40,7 +40,7 @@ Favicons::~Favicons () ***/ QString -Favicons::getCacheDir () +FaviconCache::getCacheDir () { const QString base = #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) @@ -53,7 +53,7 @@ Favicons::getCacheDir () } void -Favicons::ensureCacheDirHasBeenScanned () +FaviconCache::ensureCacheDirHasBeenScanned () { static bool hasBeenScanned = false; @@ -76,7 +76,7 @@ Favicons::ensureCacheDirHasBeenScanned () } QString -Favicons::getHost (const QUrl& url) +FaviconCache::getHost (const QUrl& url) { QString host = url.host (); const int first_dot = host.indexOf (QLatin1Char ('.')); @@ -89,19 +89,19 @@ Favicons::getHost (const QUrl& url) } QSize -Favicons::getIconSize () +FaviconCache::getIconSize () { return QSize (16, 16); } QPixmap -Favicons::find (const QUrl& url) +FaviconCache::find (const QUrl& url) { return findFromHost (getHost (url)); } QPixmap -Favicons::findFromHost (const QString& host) +FaviconCache::findFromHost (const QString& host) { ensureCacheDirHasBeenScanned (); @@ -111,7 +111,7 @@ Favicons::findFromHost (const QString& host) } void -Favicons::add (const QUrl& url) +FaviconCache::add (const QUrl& url) { ensureCacheDirHasBeenScanned (); @@ -132,7 +132,7 @@ Favicons::add (const QUrl& url) } void -Favicons::onRequestFinished (QNetworkReply * reply) +FaviconCache::onRequestFinished (QNetworkReply * reply) { const QString host = reply->url().host(); diff --git a/qt/favicon.h b/qt/FaviconCache.h similarity index 82% rename from qt/favicon.h rename to qt/FaviconCache.h index 585c2fe58..06eaeb430 100644 --- a/qt/favicon.h +++ b/qt/FaviconCache.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,19 +7,19 @@ * $Id$ */ -#ifndef FAVICON_CACHE_H -#define FAVICON_CACHE_H - -class QNetworkAccessManager; -class QNetworkReply; -class QUrl; +#ifndef QTR_FAVICON_CACHE_H +#define QTR_FAVICON_CACHE_H #include #include #include #include -class Favicons: public QObject +class QNetworkAccessManager; +class QNetworkReply; +class QUrl; + +class FaviconCache: public QObject { Q_OBJECT @@ -30,8 +30,8 @@ class Favicons: public QObject public: - Favicons(); - virtual ~Favicons(); + FaviconCache(); + virtual ~FaviconCache(); // returns a cached pixmap, or a NULL pixmap if there's no match in the cache QPixmap find (const QUrl& url); @@ -59,4 +59,4 @@ class Favicons: public QObject void onRequestFinished (QNetworkReply * reply); }; -#endif +#endif // QTR_FAVICON_CACHE_H diff --git a/qt/FileTreeDelegate.cc b/qt/FileTreeDelegate.cc new file mode 100644 index 000000000..a08f2c2fa --- /dev/null +++ b/qt/FileTreeDelegate.cc @@ -0,0 +1,90 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include + +#include "FileTreeDelegate.h" +#include "FileTreeModel.h" + +QSize +FileTreeDelegate::sizeHint(const QStyleOptionViewItem& item, const QModelIndex& index) const +{ + QSize size; + + switch(index.column()) + { + case FileTreeModel::COL_PROGRESS: + case FileTreeModel::COL_WANTED: + size = QSize(20, 1); + break; + + default: + size = QItemDelegate::sizeHint (item, index); + } + + size.rheight() += 8; // make the spacing a little nicer + return size; +} + +void +FileTreeDelegate::paint (QPainter * painter, + const QStyleOptionViewItem & option, + const QModelIndex & index) const +{ + const int column(index.column()); + + if ((column != FileTreeModel::COL_PROGRESS) && (column != FileTreeModel::COL_WANTED)) + { + QItemDelegate::paint(painter, option, index); + return; + } + + QStyle * style (qApp->style ()); + + painter->save(); + QItemDelegate::drawBackground (painter, option, index); + + if(column == FileTreeModel::COL_PROGRESS) + { + QStyleOptionProgressBar p; + p.state = option.state | QStyle::State_Small; + p.direction = qApp->layoutDirection(); + p.rect = option.rect; + p.rect.setSize (QSize(option.rect.width()-2, option.rect.height()-8)); + p.rect.moveCenter (option.rect.center()); + p.fontMetrics = qApp->fontMetrics(); + p.minimum = 0; + p.maximum = 100; + p.textAlignment = Qt::AlignCenter; + p.textVisible = true; + p.progress = (int)(100.0*index.data().toDouble()); + p.text = QString::fromLatin1 ("%1%").arg (p.progress); + style->drawControl(QStyle::CE_ProgressBar, &p, painter); + } + else if(column == FileTreeModel::COL_WANTED) + { + QStyleOptionButton o; + o.state = option.state; + o.direction = qApp->layoutDirection(); + o.rect.setSize (QSize(20, option.rect.height())); + o.rect.moveCenter (option.rect.center()); + o.fontMetrics = qApp->fontMetrics(); + switch (index.data().toInt()) + { + case Qt::Unchecked: o.state |= QStyle::State_Off; break; + case Qt::Checked: o.state |= QStyle::State_On; break; + default: o.state |= QStyle::State_NoChange;break; + } + style->drawControl (QStyle::CE_CheckBox, &o, painter); + } + + QItemDelegate::drawFocus (painter, option, option.rect); + painter->restore(); +} diff --git a/qt/FileTreeDelegate.h b/qt/FileTreeDelegate.h new file mode 100644 index 000000000..29d81ad86 --- /dev/null +++ b/qt/FileTreeDelegate.h @@ -0,0 +1,28 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_FILE_TREE_DELEGATE_H +#define QTR_FILE_TREE_DELEGATE_H + +#include + +class FileTreeDelegate: public QItemDelegate +{ + Q_OBJECT + + public: + FileTreeDelegate (QObject * parent=0): QItemDelegate(parent) {} + virtual ~FileTreeDelegate() {} + + public: + virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const; + virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const; +}; + +#endif // QTR_FILE_TREE_DELEGATE_H diff --git a/qt/FileTreeItem.cc b/qt/FileTreeItem.cc new file mode 100644 index 000000000..06a9b5d3e --- /dev/null +++ b/qt/FileTreeItem.cc @@ -0,0 +1,386 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include + +#include +#include + +#include // priorities + +#include "FileTreeItem.h" +#include "FileTreeModel.h" +#include "Formatter.h" +#include "Utils.h" // mime icons + +const QHash& +FileTreeItem::getMyChildRows () +{ + const size_t n = childCount(); + + // ensure that all the rows are hashed + while (myFirstUnhashedRow < n) + { + myChildRows.insert (myChildren[myFirstUnhashedRow]->name(), + myFirstUnhashedRow); + ++myFirstUnhashedRow; + } + + return myChildRows; +} + + +FileTreeItem::~FileTreeItem () +{ + assert(myChildren.isEmpty()); + + if (myParent != 0) + { + const int pos = row(); + assert ((pos>=0) && "couldn't find child in parent's lookup"); + myParent->myChildren.removeAt(pos); + myParent->myChildRows.remove(name()); + myParent->myFirstUnhashedRow = pos; + } +} + +void +FileTreeItem::appendChild (FileTreeItem * child) +{ + const size_t n = childCount(); + child->myParent = this; + myChildren.append (child); + myFirstUnhashedRow = n; +} + +FileTreeItem * +FileTreeItem::child (const QString& filename) +{ + FileTreeItem * item(0); + + const int row = getMyChildRows().value (filename, -1); + if (row != -1) + { + item = child (row); + assert (filename == item->name()); + } + + return item; +} + +int +FileTreeItem::row () const +{ + int i(-1); + + if(myParent) + { + i = myParent->getMyChildRows().value (name(), -1); + assert (this == myParent->myChildren[i]); + } + + return i; +} + +QVariant +FileTreeItem::data (int column, int role) const +{ + QVariant value; + + if (column == FileTreeModel::COL_FILE_INDEX) + { + value.setValue (myFileIndex); + } + else if (role == Qt::EditRole) + { + if (column == 0) + value.setValue (name()); + } + else if ((role == Qt::TextAlignmentRole) && column == FileTreeModel::COL_SIZE) + { + value = Qt::AlignRight + Qt::AlignVCenter; + } + else if (role == Qt::DisplayRole) + { + switch(column) + { + case FileTreeModel::COL_NAME: + value.setValue (name()); + break; + + case FileTreeModel::COL_SIZE: + value.setValue (sizeString() + QLatin1String (" ")); + break; + + case FileTreeModel::COL_PROGRESS: + value.setValue (progress()); + break; + + case FileTreeModel::COL_WANTED: + value.setValue (isSubtreeWanted()); + break; + + case FileTreeModel::COL_PRIORITY: + value.setValue (priorityString()); + break; + } + } + else if (role == Qt::DecorationRole && column == FileTreeModel::COL_NAME) + { + if (childCount () > 0) + value = qApp->style ()->standardIcon (QStyle::SP_DirOpenIcon); + else + value = Utils::guessMimeIcon (name ()); + } + + return value; +} + +void +FileTreeItem::getSubtreeWantedSize (uint64_t& have, uint64_t& total) const +{ + if (myIsWanted) + { + have += myHaveSize; + total += myTotalSize; + } + + for (const FileTreeItem * const i: myChildren) + i->getSubtreeWantedSize(have, total); +} + +double +FileTreeItem::progress () const +{ + double d(0); + uint64_t have(0), total(0); + + getSubtreeWantedSize (have, total); + if (total) + d = have / (double)total; + + return d; +} + +QString +FileTreeItem::sizeString () const +{ + QString str; + + if (myChildren.isEmpty()) + { + str = Formatter::sizeToString (myTotalSize); + } + else + { + uint64_t have = 0; + uint64_t total = 0; + getSubtreeWantedSize (have, total); + str = Formatter::sizeToString (total); + } + + return str; +} + +std::pair +FileTreeItem::update (const QString& name, + bool wanted, + int priority, + uint64_t haveSize, + bool updateFields) +{ + int changed_count = 0; + int changed_columns[4]; + + if (myName != name) + { + if (myParent) + myParent->myFirstUnhashedRow = row(); + + myName = name; + changed_columns[changed_count++] = FileTreeModel::COL_NAME; + } + + if (fileIndex () != -1) + { + if (myHaveSize != haveSize) + { + myHaveSize = haveSize; + changed_columns[changed_count++] = FileTreeModel::COL_PROGRESS; + } + + if (updateFields) + { + if (myIsWanted != wanted) + { + myIsWanted = wanted; + changed_columns[changed_count++] = FileTreeModel::COL_WANTED; + } + + if (myPriority != priority) + { + myPriority = priority; + changed_columns[changed_count++] = FileTreeModel::COL_PRIORITY; + } + } + } + + std::pair changed (-1, -1); + if (changed_count > 0) + { + std::sort (changed_columns, changed_columns+changed_count); + changed.first = changed_columns[0]; + changed.second = changed_columns[changed_count-1]; + } + return changed; +} + +QString +FileTreeItem::priorityString () const +{ + const int i = priority(); + + switch (i) + { + case LOW: return tr("Low"); + case HIGH: return tr("High"); + case NORMAL: return tr("Normal"); + default: return tr("Mixed"); + } +} + +int +FileTreeItem::priority () const +{ + int i(0); + + if (myChildren.isEmpty()) + { + switch (myPriority) + { + case TR_PRI_LOW: + i |= LOW; + break; + + case TR_PRI_HIGH: + i |= HIGH; + break; + + default: + i |= NORMAL; + break; + } + } + + for (const FileTreeItem * const child: myChildren) + i |= child->priority(); + + return i; +} + +void +FileTreeItem::setSubtreePriority (int i, QSet& ids) +{ + if (myPriority != i) + { + myPriority = i; + + if (myFileIndex >= 0) + ids.insert (myFileIndex); + } + + for (FileTreeItem * const child: myChildren) + child->setSubtreePriority (i, ids); +} + +void +FileTreeItem::twiddlePriority (QSet& ids, int& p) +{ + const int old(priority()); + + if (old & LOW) + p = TR_PRI_NORMAL; + else if (old & NORMAL) + p = TR_PRI_HIGH; + else + p = TR_PRI_LOW; + + setSubtreePriority (p, ids); +} + +int +FileTreeItem::isSubtreeWanted () const +{ + if(myChildren.isEmpty()) + return myIsWanted ? Qt::Checked : Qt::Unchecked; + + int wanted(-1); + for (const FileTreeItem * const child: myChildren) + { + const int childWanted = child->isSubtreeWanted(); + + if (wanted == -1) + wanted = childWanted; + + if (wanted != childWanted) + wanted = Qt::PartiallyChecked; + + if (wanted == Qt::PartiallyChecked) + return wanted; + } + + return wanted; +} + +void +FileTreeItem::setSubtreeWanted (bool b, QSet& ids) +{ + if (myIsWanted != b) + { + myIsWanted = b; + + if (myFileIndex >= 0) + ids.insert(myFileIndex); + } + + for (FileTreeItem * const child: myChildren) + child->setSubtreeWanted (b, ids); +} + +void +FileTreeItem::twiddleWanted (QSet& ids, bool& wanted) +{ + wanted = isSubtreeWanted() != Qt::Checked; + setSubtreeWanted (wanted, ids); +} + +QString +FileTreeItem::path () const +{ + QString itemPath; + const FileTreeItem * item = this; + + while (item != NULL && !item->name().isEmpty()) + { + if (itemPath.isEmpty()) + itemPath = item->name(); + else + itemPath = item->name() + QLatin1Char ('/') + itemPath; + item = item->parent (); + } + + return itemPath; +} + +bool +FileTreeItem::isComplete () const +{ + return myHaveSize == totalSize (); +} diff --git a/qt/FileTreeItem.h b/qt/FileTreeItem.h new file mode 100644 index 000000000..74114e079 --- /dev/null +++ b/qt/FileTreeItem.h @@ -0,0 +1,83 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_FILE_TREE_ITEM_H +#define QTR_FILE_TREE_ITEM_H + +#include + +#include +#include +#include +#include +#include +#include + +class FileTreeItem: public QObject +{ + Q_OBJECT + + enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) }; + + public: + + virtual ~FileTreeItem(); + + FileTreeItem (const QString& name=QString (), int fileIndex=-1, uint64_t size=0): + myFileIndex (fileIndex), + myParent (0), + myName (name), + myPriority (0), + myIsWanted (0), + myHaveSize (0), + myTotalSize (size), + myFirstUnhashedRow (0) {} + + public: + void appendChild (FileTreeItem *child); + FileTreeItem * child (const QString& filename); + FileTreeItem * child (int row) { return myChildren.at(row); } + int childCount () const { return myChildren.size(); } + FileTreeItem * parent () { return myParent; } + const FileTreeItem * parent () const { return myParent; } + int row () const; + const QString& name () const { return myName; } + QVariant data (int column, int role) const; + std::pair update (const QString& name, bool want, int priority, uint64_t have, bool updateFields); + void twiddleWanted (QSet& fileIds, bool&); + void twiddlePriority (QSet& fileIds, int&); + int fileIndex () const { return myFileIndex; } + uint64_t totalSize () const { return myTotalSize; } + QString path () const; + bool isComplete () const; + + private: + void setSubtreePriority (int priority, QSet& fileIds); + void setSubtreeWanted (bool, QSet& fileIds); + QString priorityString () const; + QString sizeString () const; + void getSubtreeWantedSize (uint64_t& have, uint64_t& total) const; + double progress () const; + int priority () const; + int isSubtreeWanted () const; + + const int myFileIndex; + FileTreeItem * myParent; + QList myChildren; + QHash myChildRows; + const QHash& getMyChildRows(); + QString myName; + int myPriority; + bool myIsWanted; + uint64_t myHaveSize; + const uint64_t myTotalSize; + size_t myFirstUnhashedRow; +}; + +#endif // QTR_FILE_TREE_ITEM_H diff --git a/qt/FileTreeModel.cc b/qt/FileTreeModel.cc new file mode 100644 index 000000000..2807d7491 --- /dev/null +++ b/qt/FileTreeModel.cc @@ -0,0 +1,386 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include + +#include + +#include "FileTreeItem.h" +#include "FileTreeModel.h" + +FileTreeModel::FileTreeModel (QObject * parent, bool isEditable): + QAbstractItemModel(parent), + myRootItem (new FileTreeItem), + myIndexCache (), + myIsEditable (isEditable) +{ +} + +FileTreeModel::~FileTreeModel() +{ + clear(); + + delete myRootItem; +} + +void +FileTreeModel::setEditable (bool editable) +{ + myIsEditable = editable; +} + +FileTreeItem * +FileTreeModel::itemFromIndex (const QModelIndex& index) const +{ + return static_cast(index.internalPointer()); +} + +QVariant +FileTreeModel::data (const QModelIndex &index, int role) const +{ + QVariant value; + + if (index.isValid()) + value = itemFromIndex(index)->data (index.column(), role); + + return value; +} + +Qt::ItemFlags +FileTreeModel::flags (const QModelIndex& index) const +{ + int i(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + if(myIsEditable && (index.column() == COL_NAME)) + i |= Qt::ItemIsEditable; + + if(index.column() == COL_WANTED) + i |= Qt::ItemIsUserCheckable | Qt::ItemIsTristate; + + return (Qt::ItemFlags)i; +} + +bool +FileTreeModel::setData (const QModelIndex& index, const QVariant& newname, int role) +{ + if (role == Qt::EditRole) + { + FileTreeItem * item = itemFromIndex (index); + + emit pathEdited (item->path (), newname.toString ()); + } + + return false; // don't update the view until the session confirms the change +} + +QVariant +FileTreeModel::headerData (int column, Qt::Orientation orientation, int role) const +{ + QVariant data; + + if (orientation==Qt::Horizontal && role==Qt::DisplayRole) + { + switch (column) + { + case COL_NAME: + data.setValue (tr("File")); + break; + + case COL_SIZE: + data.setValue (tr("Size")); + break; + + case COL_PROGRESS: + data.setValue (tr("Progress")); + break; + + case COL_WANTED: + data.setValue (tr("Download")); + break; + + case COL_PRIORITY: + data.setValue (tr("Priority")); + break; + + default: + break; + } + } + + return data; +} + +QModelIndex +FileTreeModel::index (int row, int column, const QModelIndex& parent) const +{ + QModelIndex i; + + if (hasIndex (row, column, parent)) + { + FileTreeItem * parentItem; + + if (!parent.isValid ()) + parentItem = myRootItem; + else + parentItem = itemFromIndex (parent); + + FileTreeItem * childItem = parentItem->child (row); + + if (childItem) + i = createIndex (row, column, childItem); + } + + return i; +} + +QModelIndex +FileTreeModel::parent (const QModelIndex& child) const +{ + return parent (child, 0); // QAbstractItemModel::parent() wants col 0 +} + +QModelIndex +FileTreeModel::parent (const QModelIndex& child, int column) const +{ + QModelIndex parent; + + if (child.isValid()) + parent = indexOf (itemFromIndex(child)->parent(), column); + + return parent; +} + +int +FileTreeModel::rowCount (const QModelIndex& parent) const +{ + FileTreeItem * parentItem; + + if (parent.isValid()) + parentItem = itemFromIndex (parent); + else + parentItem = myRootItem; + + return parentItem->childCount(); +} + +int +FileTreeModel::columnCount (const QModelIndex& parent) const +{ + Q_UNUSED(parent); + + return NUM_COLUMNS; +} + +QModelIndex +FileTreeModel::indexOf (FileTreeItem * item, int column) const +{ + if (!item || item==myRootItem) + return QModelIndex(); + + return createIndex(item->row(), column, item); +} + +void +FileTreeModel::clearSubtree (const QModelIndex& top) +{ + size_t i = rowCount (top); + + while (i > 0) + clearSubtree(index(--i, 0, top)); + + FileTreeItem * const item = itemFromIndex (top); + if (item == 0) + return; + + if (item->fileIndex () != -1) + myIndexCache.remove (item->fileIndex ()); + + delete item; +} + +void +FileTreeModel::clear () +{ + beginResetModel (); + clearSubtree (QModelIndex()); + endResetModel (); + + assert (myIndexCache.isEmpty ()); +} + +FileTreeItem * +FileTreeModel::findItemForFileIndex (int fileIndex) const +{ + return myIndexCache.value (fileIndex, 0); +} + +void +FileTreeModel::addFile (int fileIndex, + const QString & filename, + bool wanted, + int priority, + uint64_t totalSize, + uint64_t have, + QList & rowsAdded, + bool updateFields) +{ + FileTreeItem * item; + QStringList tokens = filename.split (QChar::fromLatin1('/')); + + item = findItemForFileIndex (fileIndex); + + if (item) // this file is already in the tree, we've added this + { + QModelIndex indexWithChangedParents; + while (!tokens.isEmpty()) + { + const QString token = tokens.takeLast(); + const std::pair changed = item->update (token, wanted, priority, have, updateFields); + if (changed.first >= 0) + { + dataChanged (indexOf (item, changed.first), indexOf (item, changed.second)); + if (!indexWithChangedParents.isValid () && + changed.first <= COL_PRIORITY && changed.second >= COL_SIZE) + indexWithChangedParents = indexOf (item, 0); + } + item = item->parent(); + } + assert (item == myRootItem); + if (indexWithChangedParents.isValid ()) + parentsChanged (indexWithChangedParents, COL_SIZE, COL_PRIORITY); + } + else // we haven't build the FileTreeItems for these tokens yet + { + bool added = false; + + item = myRootItem; + while (!tokens.isEmpty()) + { + const QString token = tokens.takeFirst(); + FileTreeItem * child(item->child(token)); + if (!child) + { + added = true; + QModelIndex parentIndex (indexOf(item, 0)); + const int n (item->childCount()); + + beginInsertRows (parentIndex, n, n); + if (tokens.isEmpty()) + child = new FileTreeItem (token, fileIndex, totalSize); + else + child = new FileTreeItem (token); + item->appendChild (child); + endInsertRows (); + + rowsAdded.append (indexOf(child, 0)); + } + item = child; + } + + if (item != myRootItem) + { + assert (item->fileIndex() == fileIndex); + assert (item->totalSize() == totalSize); + + myIndexCache[fileIndex] = item; + + const std::pair changed = item->update (item->name(), wanted, priority, have, added || updateFields); + if (changed.first >= 0) + dataChanged (indexOf (item, changed.first), indexOf (item, changed.second)); + } + } +} + +void +FileTreeModel::parentsChanged (const QModelIndex& index, int firstColumn, int lastColumn) +{ + assert (firstColumn <= lastColumn); + + QModelIndex walk = index; + + for (;;) + { + walk = parent (walk, firstColumn); + if (!walk.isValid ()) + break; + + dataChanged (walk, walk.sibling (walk.row (), lastColumn)); + } +} + +void +FileTreeModel::subtreeChanged (const QModelIndex& index, int firstColumn, int lastColumn) +{ + assert (firstColumn <= lastColumn); + + const int childCount = rowCount (index); + if (!childCount) + return; + + // tell everyone that this tier changed + dataChanged (index.child (0, firstColumn), index.child (childCount - 1, lastColumn)); + + // walk the subtiers + for (int i=0; i file_ids; + FileTreeItem * item; + + item = itemFromIndex (index); + item->twiddleWanted (file_ids, want); + emit wantedChanged (file_ids, want); + + dataChanged (index, index); + parentsChanged (index, COL_SIZE, COL_WANTED); + subtreeChanged (index, COL_WANTED, COL_WANTED); + } + else if (column == COL_PRIORITY) + { + int priority; + QSet file_ids; + FileTreeItem * item; + + item = itemFromIndex (index); + item->twiddlePriority (file_ids, priority); + emit priorityChanged (file_ids, priority); + + dataChanged (index, index); + parentsChanged (index, column, column); + subtreeChanged (index, column, column); + } +} + +void +FileTreeModel::doubleClicked (const QModelIndex& index) +{ + if (!index.isValid()) + return; + + const int column (index.column()); + if (column == COL_WANTED || column == COL_PRIORITY) + return; + + FileTreeItem * item = itemFromIndex (index); + + if (item->childCount () == 0 && item->isComplete ()) + emit openRequested (item->path ()); +} diff --git a/qt/FileTreeModel.h b/qt/FileTreeModel.h new file mode 100644 index 000000000..ec5b8e382 --- /dev/null +++ b/qt/FileTreeModel.h @@ -0,0 +1,90 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_FILE_TREE_MODEL_H +#define QTR_FILE_TREE_MODEL_H + +#include + +#include +#include +#include +#include + +class FileTreeItem; + +class FileTreeModel: public QAbstractItemModel +{ + Q_OBJECT + + public: + enum + { + COL_NAME, + FIRST_VISIBLE_COLUMN = COL_NAME, + COL_SIZE, + COL_PROGRESS, + COL_WANTED, + COL_PRIORITY, + LAST_VISIBLE_COLUMN = COL_PRIORITY, + + COL_FILE_INDEX, + NUM_COLUMNS + }; + + public: + FileTreeModel (QObject *parent = 0, bool isEditable = true); + ~FileTreeModel (); + + void setEditable (bool editable); + + public: + QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const; + Qt::ItemFlags flags (const QModelIndex& index) const; + QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const; + QModelIndex parent (const QModelIndex& child) const; + QModelIndex parent (const QModelIndex& child, int column) const; + int rowCount (const QModelIndex& parent = QModelIndex()) const; + int columnCount (const QModelIndex &parent = QModelIndex()) const; + virtual bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); + + signals: + void priorityChanged (const QSet& fileIndices, int); + void wantedChanged (const QSet& fileIndices, bool); + void pathEdited (const QString& oldpath, const QString& newname); + void openRequested (const QString& path); + + public: + void clear (); + void addFile (int index, const QString& filename, + bool wanted, int priority, + uint64_t size, uint64_t have, + QList& rowsAdded, + bool torrentChanged); + + private: + void clearSubtree (const QModelIndex &); + QModelIndex indexOf (FileTreeItem *, int column) const; + void parentsChanged (const QModelIndex &, int firstColumn, int lastColumn); + void subtreeChanged (const QModelIndex &, int firstColumn, int lastColumn); + FileTreeItem * findItemForFileIndex (int fileIndex) const; + FileTreeItem * itemFromIndex (const QModelIndex&) const; + + private: + FileTreeItem * myRootItem; + QMap myIndexCache; + bool myIsEditable; + + public slots: + void clicked (const QModelIndex & index); + void doubleClicked (const QModelIndex & index); +}; + +#endif // QTR_FILE_TREE_MODEL_H diff --git a/qt/FileTreeView.cc b/qt/FileTreeView.cc new file mode 100644 index 000000000..17f0620ca --- /dev/null +++ b/qt/FileTreeView.cc @@ -0,0 +1,167 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include + +#include +#include +#include + +#include "FileTreeDelegate.h" +#include "FileTreeModel.h" +#include "FileTreeView.h" + +FileTreeView::FileTreeView (QWidget * parent, bool isEditable): + QTreeView (parent), + myModel (new FileTreeModel (this, isEditable)), + myProxy (new QSortFilterProxyModel (this)), + myDelegate (new FileTreeDelegate (this)) +{ + setSortingEnabled (true); + setAlternatingRowColors (true); + setSelectionBehavior (QAbstractItemView::SelectRows); + setSelectionMode (QAbstractItemView::ExtendedSelection); + myProxy->setSourceModel (myModel); + setModel (myProxy); + setItemDelegate (myDelegate); + setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); + sortByColumn (FileTreeModel::COL_NAME, Qt::AscendingOrder); + installEventFilter (this); + + for (int i=0; isetResizeMode(i, QHeaderView::Interactive); +#else + header()->setSectionResizeMode(i, QHeaderView::Interactive); +#endif + } + + connect (this, SIGNAL(clicked(QModelIndex)), + this, SLOT(onClicked(QModelIndex))); + + connect (this, SIGNAL(doubleClicked(QModelIndex)), + this, SLOT(onDoubleClicked(QModelIndex))); + + connect (myModel, SIGNAL(priorityChanged(QSet, int)), + this, SIGNAL(priorityChanged(QSet, int))); + + connect (myModel, SIGNAL(wantedChanged(QSet, bool)), + this, SIGNAL(wantedChanged(QSet, bool))); + + connect (myModel, SIGNAL(pathEdited(QString, QString)), + this, SIGNAL(pathEdited(QString, QString))); + + connect (myModel, SIGNAL (openRequested (QString)), + this, SLOT (onOpenRequested (QString)), + Qt::QueuedConnection); +} + +void +FileTreeView::onClicked (const QModelIndex& proxyIndex) +{ + const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex); + myModel->clicked (modelIndex); +} + +void +FileTreeView::onDoubleClicked (const QModelIndex& proxyIndex) +{ + const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex); + myModel->doubleClicked (modelIndex); +} + +void +FileTreeView::onOpenRequested (const QString& path) +{ + if (state () == EditingState) + return; + + emit openRequested (path); +} + +bool +FileTreeView::eventFilter (QObject * o, QEvent * event) +{ + // this is kind of a hack to get the last three columns be the + // right size, and to have the filename column use whatever + // space is left over... + if ((o == this) && (event->type() == QEvent::Resize)) + { + QResizeEvent * r = static_cast (event); + int left = r->size().width(); + const QFontMetrics fontMetrics(font()); + for (int column=FileTreeModel::FIRST_VISIBLE_COLUMN; column<=FileTreeModel::LAST_VISIBLE_COLUMN; ++column) + { + if (column == FileTreeModel::COL_NAME) + continue; + if (isColumnHidden (column)) + continue; + + QString header; + if (column == FileTreeModel::COL_SIZE) + header = QLatin1String ("999.9 KiB"); + else + header = myModel->headerData (column, Qt::Horizontal).toString(); + header += QLatin1String (" "); + const int width = fontMetrics.size (0, header).width(); + setColumnWidth (column, width); + left -= width; + } + left -= 20; // not sure why this is necessary. it works in different themes + font sizes though... + setColumnWidth(FileTreeModel::COL_NAME, std::max(left,0)); + } + + // handle using the keyboard to toggle the + // wanted/unwanted state or the file priority + else if (event->type () == QEvent::KeyPress && state () != EditingState) + { + switch (static_cast (event)->key ()) + { + case Qt::Key_Space: + for (const QModelIndex& i: selectionModel ()->selectedRows (FileTreeModel::COL_WANTED)) + clicked (i); + break; + + case Qt::Key_Enter: + case Qt::Key_Return: + for (const QModelIndex& i: selectionModel ()->selectedRows (FileTreeModel::COL_PRIORITY)) + clicked (i); + break; + } + } + + return false; +} + +void +FileTreeView::update (const FileList& files, bool updateFields) +{ + for (const TorrentFile& file: files) + { + QList added; + myModel->addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, updateFields); + for (const QModelIndex& i: added) + expand (myProxy->mapFromSource(i)); + } +} + +void +FileTreeView::clear () +{ + myModel->clear(); +} + +void +FileTreeView::setEditable (bool editable) +{ + myModel->setEditable (editable); +} diff --git a/qt/FileTreeView.h b/qt/FileTreeView.h new file mode 100644 index 000000000..aadd7041b --- /dev/null +++ b/qt/FileTreeView.h @@ -0,0 +1,54 @@ +/* + * This file Copyright (C) 2009-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_FILE_TREE_VIEW_H +#define QTR_FILE_TREE_VIEW_H + +#include +#include + +#include "Torrent.h" // FileList + +class QSortFilterProxyModel; + +class FileTreeDelegate; +class FileTreeModel; + +class FileTreeView: public QTreeView +{ + Q_OBJECT + + public: + FileTreeView (QWidget * parent=0, bool editable=true); + void clear (); + void update (const FileList& files, bool updateProperties=true); + + void setEditable (bool editable); + + signals: + void priorityChanged (const QSet& fileIndices, int priority); + void wantedChanged (const QSet& fileIndices, bool wanted); + void pathEdited (const QString& oldpath, const QString& newname); + void openRequested (const QString& path); + + protected: + bool eventFilter (QObject *, QEvent *); + + private: + FileTreeModel * myModel; + QSortFilterProxyModel * myProxy; + FileTreeDelegate * myDelegate; + + public slots: + void onClicked (const QModelIndex& index); + void onDoubleClicked (const QModelIndex& index); + void onOpenRequested (const QString& path); +}; + +#endif // QTR_FILE_TREE_VIEW_H diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc new file mode 100644 index 000000000..b420c8595 --- /dev/null +++ b/qt/FilterBar.cc @@ -0,0 +1,410 @@ +/* + * This file Copyright (C) 2012-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include +#include + +#include "Application.h" +#include "FaviconCache.h" +#include "Filters.h" +#include "FilterBar.h" +#include "FilterBarComboBox.h" +#include "FilterBarComboBoxDelegate.h" +#include "FilterBarLineEdit.h" +#include "Prefs.h" +#include "TorrentFilter.h" +#include "TorrentModel.h" + +enum +{ + ActivityRole = FilterBarComboBox::UserRole, + TrackerRole +}; + +namespace +{ + QString + readableHostName (const QString& host) + { + // get the readable name... + QString name = host; + const int pos = name.lastIndexOf (QLatin1Char ('.')); + if (pos >= 0) + name.truncate (pos); + if (!name.isEmpty ()) + name[0] = name[0].toUpper (); + return name; + } +} + +/*** +**** +***/ + +FilterBarComboBox * +FilterBar::createActivityCombo () +{ + FilterBarComboBox * c = new FilterBarComboBox (this); + FilterBarComboBoxDelegate * delegate = new FilterBarComboBoxDelegate (this, c); + c->setItemDelegate (delegate); + + QStandardItemModel * model = new QStandardItemModel (this); + + QStandardItem * row = new QStandardItem (tr ("All")); + row->setData (FilterMode::SHOW_ALL, ActivityRole); + model->appendRow (row); + + model->appendRow (new QStandardItem); // separator + delegate->setSeparator (model, model->index (1, 0)); + + row = new QStandardItem (QIcon::fromTheme (QLatin1String ("system-run")), tr ("Active")); + row->setData (FilterMode::SHOW_ACTIVE, ActivityRole); + model->appendRow (row); + + row = new QStandardItem (QIcon::fromTheme (QLatin1String ("go-down")), tr ("Downloading")); + row->setData (FilterMode::SHOW_DOWNLOADING, ActivityRole); + model->appendRow (row); + + row = new QStandardItem (QIcon::fromTheme (QLatin1String ("go-up")), tr ("Seeding")); + row->setData (FilterMode::SHOW_SEEDING, ActivityRole); + model->appendRow (row); + + row = new QStandardItem (QIcon::fromTheme (QLatin1String ("media-playback-pause")), tr ("Paused")); + row->setData (FilterMode::SHOW_PAUSED, ActivityRole); + model->appendRow (row); + + row = new QStandardItem (QIcon::fromTheme (QLatin1String ("dialog-ok")), tr ("Finished")); + row->setData (FilterMode::SHOW_FINISHED, ActivityRole); + model->appendRow (row); + + row = new QStandardItem (QIcon::fromTheme (QLatin1String ("view-refresh")), tr ("Verifying")); + row->setData (FilterMode::SHOW_VERIFYING, ActivityRole); + model->appendRow (row); + + row = new QStandardItem (QIcon::fromTheme (QLatin1String ("process-stop")), tr ("Error")); + row->setData (FilterMode::SHOW_ERROR, ActivityRole); + model->appendRow (row); + + c->setModel (model); + return c; +} + +/*** +**** +***/ + +void +FilterBar::refreshTrackers () +{ + FaviconCache& favicons = qApp->favicons; + const int firstTrackerRow = 2; // skip over the "All" and separator... + + // pull info from the tracker model... + QSet oldHosts; + for (int row=firstTrackerRow; ; ++row) + { + QModelIndex index = myTrackerModel->index (row, 0); + if (!index.isValid ()) + break; + oldHosts << index.data (TrackerRole).toString (); + } + + // pull the new stats from the torrent model... + QSet newHosts; + QMap torrentsPerHost; + for (int row=0; ; ++row) + { + QModelIndex index = myTorrents.index (row, 0); + if (!index.isValid ()) + break; + const Torrent * tor = index.data (TorrentModel::TorrentRole).value (); + QSet torrentNames; + for (const QString& host: tor->hosts ()) + { + newHosts.insert (host); + torrentNames.insert (readableHostName (host)); + } + for (const QString& name: torrentNames) + ++torrentsPerHost[name]; + } + + // update the "All" row + myTrackerModel->setData (myTrackerModel->index (0,0), myTorrents.rowCount (), FilterBarComboBox::CountRole); + myTrackerModel->setData (myTrackerModel->index (0,0), getCountString (myTorrents.rowCount ()), FilterBarComboBox::CountStringRole); + + // rows to update + for (const QString& host: oldHosts & newHosts) + { + const QString name = readableHostName (host); + QStandardItem * row = myTrackerModel->findItems (name).front (); + const int count = torrentsPerHost[name]; + row->setData (count, FilterBarComboBox::CountRole); + row->setData (getCountString (count), FilterBarComboBox::CountStringRole); + row->setData (favicons.findFromHost (host), Qt::DecorationRole); + } + + // rows to remove + for (const QString& host: oldHosts - newHosts) + { + const QString name = readableHostName (host); + QStandardItem * item = myTrackerModel->findItems (name).front (); + if (!item->data (TrackerRole).toString ().isEmpty ()) // don't remove "All" + myTrackerModel->removeRows (item->row (), 1); + } + + // rows to add + bool anyAdded = false; + for (const QString& host: newHosts - oldHosts) + { + const QString name = readableHostName (host); + + if (!myTrackerModel->findItems (name).isEmpty ()) + continue; + + // find the sorted position to add this row + int i = firstTrackerRow; + for (int n=myTrackerModel->rowCount (); iindex (i,0).data (Qt::DisplayRole).toString (); + if (rowName >= name) + break; + } + + // add the row + QStandardItem * row = new QStandardItem (favicons.findFromHost (host), name); + const int count = torrentsPerHost[host]; + row->setData (count, FilterBarComboBox::CountRole); + row->setData (getCountString (count), FilterBarComboBox::CountStringRole); + row->setData (favicons.findFromHost (host), Qt::DecorationRole); + row->setData (host, TrackerRole); + myTrackerModel->insertRow (i, row); + anyAdded = true; + } + + if (anyAdded) // the one added might match our filter... + refreshPref (Prefs::FILTER_TRACKERS); +} + + +FilterBarComboBox * +FilterBar::createTrackerCombo (QStandardItemModel * model) +{ + FilterBarComboBox * c = new FilterBarComboBox (this); + FilterBarComboBoxDelegate * delegate = new FilterBarComboBoxDelegate (this, c); + c->setItemDelegate (delegate); + + QStandardItem * row = new QStandardItem (tr ("All")); + row->setData (QString (), TrackerRole); + const int count = myTorrents.rowCount (); + row->setData (count, FilterBarComboBox::CountRole); + row->setData (getCountString (count), FilterBarComboBox::CountStringRole); + model->appendRow (row); + + model->appendRow (new QStandardItem); // separator + delegate->setSeparator (model, model->index (1, 0)); + + c->setModel (model); + return c; +} + +/*** +**** +***/ + +FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentFilter& filter, QWidget * parent): + QWidget (parent), + myPrefs (prefs), + myTorrents (torrents), + myFilter (filter), + myRecountTimer (new QTimer (this)), + myIsBootstrapping (true) +{ + QHBoxLayout * h = new QHBoxLayout (this); + h->setContentsMargins (3, 3, 3, 3); + + myCountLabel = new QLabel (this); + h->addWidget (myCountLabel); + + myActivityCombo = createActivityCombo (); + myActivityCombo->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); + h->addWidget (myActivityCombo); + + myTrackerModel = new QStandardItemModel (this); + myTrackerCombo = createTrackerCombo (myTrackerModel); + h->addWidget (myTrackerCombo); + + myLineEdit = new FilterBarLineEdit (this); + h->addWidget (myLineEdit); + connect (myLineEdit, SIGNAL (textChanged (QString)), this, SLOT (onTextChanged (QString))); + + // listen for changes from the other players + connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (int))); + connect (myActivityCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onActivityIndexChanged (int))); + connect (myTrackerCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onTrackerIndexChanged (int))); + connect (&myFilter, SIGNAL (rowsInserted (QModelIndex, int, int)), this, SLOT (refreshCountLabel ())); + connect (&myFilter, SIGNAL (rowsRemoved (QModelIndex, int, int)), this, SLOT (refreshCountLabel ())); + connect (&myTorrents, SIGNAL (modelReset ()), this, SLOT (onTorrentModelReset ())); + connect (&myTorrents, SIGNAL (rowsInserted (QModelIndex, int, int)), this, SLOT (onTorrentModelRowsInserted (QModelIndex, int, int))); + connect (&myTorrents, SIGNAL (rowsRemoved (QModelIndex, int, int)), this, SLOT (onTorrentModelRowsRemoved (QModelIndex, int, int))); + connect (&myTorrents, SIGNAL (dataChanged (QModelIndex, QModelIndex)), this, SLOT (onTorrentModelDataChanged (QModelIndex, QModelIndex))); + connect (myRecountTimer, SIGNAL (timeout ()), this, SLOT (recount ())); + + recountSoon (); + refreshTrackers (); + refreshCountLabel (); + myIsBootstrapping = false; + + // initialize our state + QList initKeys; + initKeys << Prefs::FILTER_MODE + << Prefs::FILTER_TRACKERS; + for (const int key: initKeys) + refreshPref (key); +} + +FilterBar::~FilterBar () +{ + delete myRecountTimer; +} + +/*** +**** +***/ + +void +FilterBar::refreshPref (int key) +{ + switch (key) + { + case Prefs::FILTER_MODE: + { + const FilterMode m = myPrefs.get (key); + QAbstractItemModel * model = myActivityCombo->model (); + QModelIndexList indices = model->match (model->index (0,0), ActivityRole, m.mode ()); + myActivityCombo->setCurrentIndex (indices.isEmpty () ? 0 : indices.first ().row ()); + break; + } + + case Prefs::FILTER_TRACKERS: + { + const QString tracker = myPrefs.getString (key); + const QString name = readableHostName (tracker); + QList rows = myTrackerModel->findItems (name); + if (!rows.isEmpty ()) + { + myTrackerCombo->setCurrentIndex (rows.front ()->row ()); + } + else // hm, we don't seem to have this tracker anymore... + { + const bool isBootstrapping = myTrackerModel->rowCount () <= 2; + if (!isBootstrapping) + myPrefs.set (key, QString ()); + } + break; + } + } +} + +void +FilterBar::onTextChanged (const QString& str) +{ + if (!myIsBootstrapping) + myPrefs.set (Prefs::FILTER_TEXT, str.trimmed ()); +} + +void +FilterBar::onTrackerIndexChanged (int i) +{ + if (!myIsBootstrapping) + { + QString str; + const bool isTracker = !myTrackerCombo->itemData (i,TrackerRole).toString ().isEmpty (); + if (!isTracker) + { + // show all + } + else + { + str = myTrackerCombo->itemData (i,TrackerRole).toString (); + const int pos = str.lastIndexOf (QLatin1Char ('.')); + if (pos >= 0) + str.truncate (pos+1); + } + myPrefs.set (Prefs::FILTER_TRACKERS, str); + } +} + +void +FilterBar::onActivityIndexChanged (int i) +{ + if (!myIsBootstrapping) + { + const FilterMode mode = myActivityCombo->itemData (i, ActivityRole).toInt (); + myPrefs.set (Prefs::FILTER_MODE, mode); + } +} + +/*** +**** +***/ + +void FilterBar::onTorrentModelReset () { recountSoon (); } +void FilterBar::onTorrentModelRowsInserted (const QModelIndex&, int, int) { recountSoon (); } +void FilterBar::onTorrentModelRowsRemoved (const QModelIndex&, int, int) { recountSoon (); } +void FilterBar::onTorrentModelDataChanged (const QModelIndex&, const QModelIndex&) { recountSoon (); } + +void +FilterBar::recountSoon () +{ + if (!myRecountTimer->isActive ()) + { + myRecountTimer->setSingleShot (true); + myRecountTimer->start (800); + } +} +void +FilterBar::recount () +{ + QAbstractItemModel * model = myActivityCombo->model (); + + int torrentsPerMode[FilterMode::NUM_MODES] = {}; + myFilter.countTorrentsPerMode (torrentsPerMode); + + for (int row=0, n=model->rowCount (); rowindex (row, 0); + const int mode = index.data (ActivityRole).toInt (); + const int count = torrentsPerMode [mode]; + model->setData (index, count, FilterBarComboBox::CountRole); + model->setData (index, getCountString (count), FilterBarComboBox::CountStringRole); + } + + refreshTrackers (); + refreshCountLabel (); +} + +QString +FilterBar::getCountString (int n) const +{ + return QString::fromLatin1 ("%L1").arg (n); +} + +void +FilterBar::refreshCountLabel () +{ + const int visibleCount = myFilter.rowCount (); + const int trackerCount = myTrackerCombo->currentCount (); + const int activityCount = myActivityCombo->currentCount (); + + if ((visibleCount == activityCount) || (visibleCount == trackerCount)) + myCountLabel->setText (tr("Show:")); + else + myCountLabel->setText (tr("Show %Ln of:", 0, visibleCount)); +} diff --git a/qt/filterbar.h b/qt/FilterBar.h similarity index 51% rename from qt/filterbar.h rename to qt/FilterBar.h index f72f38753..3d623ebaf 100644 --- a/qt/filterbar.h +++ b/qt/FilterBar.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,80 +7,21 @@ * $Id$ */ -#ifndef QTR_FILTERBAR_H -#define QTR_FILTERBAR_H +#ifndef QTR_FILTER_BAR_H +#define QTR_FILTER_BAR_H -#include -#include -#include #include class QLabel; -class QLineEdit; -class QPaintEvent; class QStandardItemModel; class QTimer; -class QToolButton; +class FilterBarComboBox; +class FilterBarLineEdit; class Prefs; class TorrentFilter; class TorrentModel; -class FilterBarComboBoxDelegate: public QItemDelegate -{ - Q_OBJECT - - public: - FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo); - - public: - static bool isSeparator (const QModelIndex &index); - static void setSeparator (QAbstractItemModel * model, const QModelIndex& index); - - protected: - virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const; - virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const; - - private: - QComboBox * myCombo; - -}; - -class FilterBarComboBox: public QComboBox -{ - Q_OBJECT - - public: - FilterBarComboBox (QWidget * parent = 0); - int currentCount () const; - - virtual QSize minimumSizeHint () const; - virtual QSize sizeHint () const; - - protected: - virtual void paintEvent (QPaintEvent * e); - - private: - QSize calculateSize (const QSize& textSize, const QSize& countSize) const; -}; - -class FilterBarLineEdit: public QLineEdit -{ - Q_OBJECT - - public: - FilterBarLineEdit (QWidget * parent = 0); - - protected: - virtual void resizeEvent (QResizeEvent * event); - - private slots: - void updateClearButtonVisibility (); - - private: - QToolButton * myClearButton; -}; - class FilterBar: public QWidget { Q_OBJECT @@ -121,4 +62,4 @@ class FilterBar: public QWidget void onTextChanged (const QString&); }; -#endif +#endif // QTR_FILTER_BAR_H diff --git a/qt/FilterBarComboBox.cc b/qt/FilterBarComboBox.cc new file mode 100644 index 000000000..e2d2ffd03 --- /dev/null +++ b/qt/FilterBarComboBox.cc @@ -0,0 +1,147 @@ +/* + * This file Copyright (C) 2012-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include +#include + +#include "FilterBarComboBox.h" +#include "Utils.h" + +namespace +{ + int + getHSpacing (const QWidget * w) + { + return qMax (3, w->style ()->pixelMetric (QStyle::PM_LayoutHorizontalSpacing, 0, w)); + } +} + +FilterBarComboBox::FilterBarComboBox (QWidget * parent): + QComboBox (parent) +{ + setSizeAdjustPolicy (QComboBox::AdjustToContents); +} + +int +FilterBarComboBox::currentCount () const +{ + int count = 0; + + const QModelIndex modelIndex = model ()->index (currentIndex (), 0, rootModelIndex ()); + if (modelIndex.isValid ()) + count = modelIndex.data (CountRole).toInt (); + + return count; +} + +QSize +FilterBarComboBox::minimumSizeHint () const +{ + QFontMetrics fm (fontMetrics ()); + const QSize textSize = fm.boundingRect (itemText (0)).size (); + const QSize countSize = fm.boundingRect (itemData (0, CountStringRole).toString ()).size (); + return calculateSize (textSize, countSize); +} + +QSize +FilterBarComboBox::sizeHint () const +{ + QFontMetrics fm (fontMetrics ()); + QSize maxTextSize (0, 0); + QSize maxCountSize (0, 0); + for (int i = 0, n = count (); i < n; ++i) + { + const QSize textSize = fm.boundingRect (itemText (i)).size (); + maxTextSize.setHeight (qMax (maxTextSize.height (), textSize.height ())); + maxTextSize.setWidth (qMax (maxTextSize.width (), textSize.width ())); + + const QSize countSize = fm.boundingRect (itemData (i, CountStringRole).toString ()).size (); + maxCountSize.setHeight (qMax (maxCountSize.height (), countSize.height ())); + maxCountSize.setWidth (qMax (maxCountSize.width (), countSize.width ())); + } + + return calculateSize (maxTextSize, maxCountSize); +} + +QSize +FilterBarComboBox::calculateSize (const QSize& textSize, const QSize& countSize) const +{ + const int hmargin = getHSpacing (this); + + QStyleOptionComboBox option; + initStyleOption (&option); + + QSize contentSize = iconSize () + QSize (4, 2); + contentSize.setHeight (qMax (contentSize.height (), textSize.height ())); + contentSize.rwidth () += hmargin + textSize.width (); + contentSize.rwidth () += hmargin + countSize.width (); + + return style ()->sizeFromContents (QStyle::CT_ComboBox, &option, contentSize, this).expandedTo (qApp->globalStrut ()); +} + +void +FilterBarComboBox::paintEvent (QPaintEvent * e) +{ + Q_UNUSED (e); + + QStylePainter painter (this); + painter.setPen (palette ().color (QPalette::Text)); + + // draw the combobox frame, focusrect and selected etc. + QStyleOptionComboBox opt; + initStyleOption (&opt); + painter.drawComplexControl (QStyle::CC_ComboBox, opt); + + // draw the icon and text + const QModelIndex modelIndex = model ()->index (currentIndex (), 0, rootModelIndex ()); + if (modelIndex.isValid ()) + { + QStyle * s = style (); + const int hmargin = getHSpacing (this); + + QRect rect = s->subControlRect (QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this); + rect.adjust (2, 1, -2, -1); + + // draw the icon + QPixmap pixmap; + QVariant variant = modelIndex.data (Qt::DecorationRole); + switch (variant.type ()) + { + case QVariant::Pixmap: pixmap = qvariant_cast (variant); break; + case QVariant::Icon: pixmap = qvariant_cast (variant).pixmap (iconSize ()); break; + default: break; + } + if (!pixmap.isNull ()) + { + const QRect iconRect = QStyle::alignedRect(opt.direction, Qt::AlignLeft | Qt::AlignVCenter, + opt.iconSize, rect); + painter.drawPixmap (iconRect.topLeft (), pixmap); + Utils::narrowRect (rect, iconRect.width () + hmargin, 0, opt.direction); + } + + // draw the count + QString text = modelIndex.data (CountStringRole).toString (); + if (!text.isEmpty ()) + { + const QPen pen = painter.pen (); + painter.setPen (Utils::getFadedColor (pen.color ())); + const QRect textRect = QStyle::alignedRect(opt.direction, Qt::AlignRight | Qt::AlignVCenter, + QSize (opt.fontMetrics.width (text), rect.height ()), rect); + painter.drawText (textRect, Qt::AlignRight | Qt::AlignVCenter, text); + Utils::narrowRect (rect, 0, textRect.width () + hmargin, opt.direction); + painter.setPen (pen); + } + + // draw the text + text = modelIndex.data (Qt::DisplayRole).toString (); + text = painter.fontMetrics ().elidedText (text, Qt::ElideRight, rect.width ()); + painter.drawText (rect, Qt::AlignLeft | Qt::AlignVCenter, text); + } +} diff --git a/qt/FilterBarComboBox.h b/qt/FilterBarComboBox.h new file mode 100644 index 000000000..56dc52ee7 --- /dev/null +++ b/qt/FilterBarComboBox.h @@ -0,0 +1,41 @@ +/* + * This file Copyright (C) 2010-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_FILTER_BAR_COMBO_BOX_H +#define QTR_FILTER_BAR_COMBO_BOX_H + +#include + +class FilterBarComboBox: public QComboBox +{ + Q_OBJECT + + public: + enum + { + CountRole = Qt::UserRole + 1, + CountStringRole, + UserRole + }; + + public: + FilterBarComboBox (QWidget * parent = 0); + int currentCount () const; + + virtual QSize minimumSizeHint () const; + virtual QSize sizeHint () const; + + protected: + virtual void paintEvent (QPaintEvent * e); + + private: + QSize calculateSize (const QSize& textSize, const QSize& countSize) const; +}; + +#endif // QTR_FILTER_BAR_COMBO_BOX_H diff --git a/qt/FilterBarComboBoxDelegate.cc b/qt/FilterBarComboBoxDelegate.cc new file mode 100644 index 000000000..aa59cf594 --- /dev/null +++ b/qt/FilterBarComboBoxDelegate.cc @@ -0,0 +1,121 @@ +/* + * This file Copyright (C) 2012-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include +#include +#include + +#include "FilterBarComboBox.h" +#include "FilterBarComboBoxDelegate.h" +#include "Utils.h" + +namespace +{ + int + getHSpacing (const QWidget * w) + { + return qMax (3, w->style ()->pixelMetric (QStyle::PM_LayoutHorizontalSpacing, 0, w)); + } +} + +FilterBarComboBoxDelegate::FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo): + QItemDelegate (parent), + myCombo (combo) +{ +} + +bool +FilterBarComboBoxDelegate::isSeparator (const QModelIndex& index) +{ + return index.data (Qt::AccessibleDescriptionRole).toString () == QLatin1String ("separator"); +} +void +FilterBarComboBoxDelegate::setSeparator (QAbstractItemModel * model, const QModelIndex& index) +{ + model->setData (index, QString::fromLatin1 ("separator"), Qt::AccessibleDescriptionRole); + + if (QStandardItemModel *m = qobject_cast (model)) + if (QStandardItem *item = m->itemFromIndex (index)) + item->setFlags (item->flags () & ~ (Qt::ItemIsSelectable|Qt::ItemIsEnabled)); +} + +void +FilterBarComboBoxDelegate::paint (QPainter * painter, + const QStyleOptionViewItem & option, + const QModelIndex & index) const +{ + if (isSeparator (index)) + { + QRect rect = option.rect; + if (const QStyleOptionViewItemV3 *v3 = qstyleoption_cast (&option)) + if (const QAbstractItemView *view = qobject_cast (v3->widget)) + rect.setWidth (view->viewport ()->width ()); + QStyleOption opt; + opt.rect = rect; + myCombo->style ()->drawPrimitive (QStyle::PE_IndicatorToolBarSeparator, &opt, painter, myCombo); + } + else + { + QStyleOptionViewItem disabledOption = option; + const QPalette::ColorRole disabledColorRole = (disabledOption.state & QStyle::State_Selected) ? + QPalette::HighlightedText : QPalette::Text; + disabledOption.palette.setColor (disabledColorRole, Utils::getFadedColor (disabledOption.palette.color (disabledColorRole))); + + QRect boundingBox = option.rect; + + const int hmargin = getHSpacing (myCombo); + boundingBox.adjust (hmargin, 0, -hmargin, 0); + + QRect decorationRect = rect (option, index, Qt::DecorationRole); + decorationRect.setSize (myCombo->iconSize ()); + decorationRect = QStyle::alignedRect (option.direction, + Qt::AlignLeft|Qt::AlignVCenter, + decorationRect.size (), boundingBox); + Utils::narrowRect (boundingBox, decorationRect.width () + hmargin, 0, option.direction); + + QRect countRect = rect (option, index, FilterBarComboBox::CountStringRole); + countRect = QStyle::alignedRect (option.direction, + Qt::AlignRight|Qt::AlignVCenter, + countRect.size (), boundingBox); + Utils::narrowRect (boundingBox, 0, countRect.width () + hmargin, option.direction); + const QRect displayRect = boundingBox; + + drawBackground (painter, option, index); + QStyleOptionViewItem option2 = option; + option2.decorationSize = myCombo->iconSize (); + drawDecoration (painter, option, decorationRect, decoration (option2,index.data (Qt::DecorationRole))); + drawDisplay (painter, option, displayRect, index.data (Qt::DisplayRole).toString ()); + drawDisplay (painter, disabledOption, countRect, index.data (FilterBarComboBox::CountStringRole).toString ()); + drawFocus (painter, option, displayRect|countRect); + } +} + +QSize +FilterBarComboBoxDelegate::sizeHint (const QStyleOptionViewItem & option, + const QModelIndex & index) const +{ + if (isSeparator (index)) + { + const int pm = myCombo->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth, 0, myCombo); + return QSize (pm, pm + 10); + } + else + { + QStyle * s = myCombo->style (); + const int hmargin = getHSpacing (myCombo); + + QSize size = QItemDelegate::sizeHint (option, index); + size.setHeight (qMax (size.height (), myCombo->iconSize ().height () + 6)); + size.rwidth () += s->pixelMetric (QStyle::PM_FocusFrameHMargin, 0, myCombo); + size.rwidth () += rect (option,index,FilterBarComboBox::CountStringRole).width (); + size.rwidth () += hmargin * 4; + return size; + } +} diff --git a/qt/FilterBarComboBoxDelegate.h b/qt/FilterBarComboBoxDelegate.h new file mode 100644 index 000000000..1e34f6816 --- /dev/null +++ b/qt/FilterBarComboBoxDelegate.h @@ -0,0 +1,37 @@ +/* + * This file Copyright (C) 2010-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_FILTER_BAR_COMBO_BOX_DELEGATE_H +#define QTR_FILTER_BAR_COMBO_BOX_DELEGATE_H + +#include + +class QAbstractItemModel; +class QComboBox; + +class FilterBarComboBoxDelegate: public QItemDelegate +{ + Q_OBJECT + + public: + FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo); + + public: + static bool isSeparator (const QModelIndex &index); + static void setSeparator (QAbstractItemModel * model, const QModelIndex& index); + + protected: + virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const; + virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const; + + private: + QComboBox * myCombo; +}; + +#endif // QTR_FILTER_BAR_COMBO_BOX_DELEGATE_H diff --git a/qt/FilterBarLineEdit.cc b/qt/FilterBarLineEdit.cc new file mode 100644 index 000000000..46e8697b6 --- /dev/null +++ b/qt/FilterBarLineEdit.cc @@ -0,0 +1,73 @@ +/* + * This file Copyright (C) 2012-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include + +#include "FilterBarLineEdit.h" + +FilterBarLineEdit::FilterBarLineEdit (QWidget * parent): + QLineEdit (parent), + myClearButton (nullptr) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const QIcon icon = QIcon::fromTheme (QLatin1String ("edit-clear"), style ()->standardIcon (QStyle::SP_DialogCloseButton)); + const int iconSize = style ()->pixelMetric (QStyle::PM_SmallIconSize); + + myClearButton = new QToolButton (this); + myClearButton->setStyleSheet (QLatin1String ("QToolButton{border:0;padding:0;margin:0}")); + myClearButton->setToolButtonStyle (Qt::ToolButtonIconOnly); + myClearButton->setFocusPolicy (Qt::NoFocus); + myClearButton->setCursor (Qt::ArrowCursor); + myClearButton->setIconSize (QSize (iconSize, iconSize)); + myClearButton->setIcon (icon); + myClearButton->setFixedSize (myClearButton->iconSize () + QSize (2, 2)); + myClearButton->hide (); + + const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); + const QSize minSizeHint = minimumSizeHint (); + const QSize buttonSize = myClearButton->size (); + + setStyleSheet (QString::fromLatin1 ("QLineEdit{padding-right:%1px}").arg (buttonSize.width () + frameWidth + 1)); + setMinimumSize (qMax (minSizeHint.width (), buttonSize.width () + frameWidth * 2 + 2), + qMax (minSizeHint.height (), buttonSize.height () + frameWidth * 2 + 2)); + + connect (this, SIGNAL (textChanged (QString)), this, SLOT (updateClearButtonVisibility ())); + connect (myClearButton, SIGNAL (clicked ()), this, SLOT (clear ())); +#else + setClearButtonEnabled (true); +#endif + +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + setPlaceholderText (tr ("Search...")); +#endif +} + +void +FilterBarLineEdit::resizeEvent (QResizeEvent * event) +{ + QLineEdit::resizeEvent (event); + +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); + const QRect editRect = rect(); + const QSize buttonSize = myClearButton->size (); + + myClearButton->move (editRect.right () - frameWidth - buttonSize.width (), + editRect.top () + (editRect.height () - buttonSize.height ()) / 2); +#endif +} + +void +FilterBarLineEdit::updateClearButtonVisibility () +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + myClearButton->setVisible (!text ().isEmpty ()); +#endif +} diff --git a/qt/FilterBarLineEdit.h b/qt/FilterBarLineEdit.h new file mode 100644 index 000000000..52e2b68a3 --- /dev/null +++ b/qt/FilterBarLineEdit.h @@ -0,0 +1,34 @@ +/* + * This file Copyright (C) 2010-2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_FILTER_BAR_LINE_EDIT_H +#define QTR_FILTER_BAR_LINE_EDIT_H + +#include + +class QToolButton; + +class FilterBarLineEdit: public QLineEdit +{ + Q_OBJECT + + public: + FilterBarLineEdit (QWidget * parent = 0); + + protected: + virtual void resizeEvent (QResizeEvent * event); + + private slots: + void updateClearButtonVisibility (); + + private: + QToolButton * myClearButton; +}; + +#endif // QTR_FILTER_BAR_LINE_EDIT_H diff --git a/qt/filters.cc b/qt/Filters.cc similarity index 94% rename from qt/filters.cc rename to qt/Filters.cc index 5e2c9cb00..4f11098e3 100644 --- a/qt/filters.cc +++ b/qt/Filters.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,7 +7,7 @@ * $Id$ */ -#include "filters.h" +#include "Filters.h" const QString FilterMode::names[NUM_MODES] = { diff --git a/qt/filters.h b/qt/Filters.h similarity index 95% rename from qt/filters.h rename to qt/Filters.h index c5c366916..cd75ae104 100644 --- a/qt/filters.h +++ b/qt/Filters.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -52,4 +52,4 @@ class SortMode Q_DECLARE_METATYPE(FilterMode) Q_DECLARE_METATYPE(SortMode) -#endif +#endif // QTR_FILTERS_H diff --git a/qt/formatter.cc b/qt/Formatter.cc similarity index 97% rename from qt/formatter.cc rename to qt/Formatter.cc index 936a7ab09..df5163115 100644 --- a/qt/formatter.cc +++ b/qt/Formatter.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -12,8 +12,8 @@ #include #include // tr_formatter -#include "formatter.h" -#include "speed.h" +#include "Formatter.h" +#include "Speed.h" /*** **** Constants diff --git a/qt/formatter.h b/qt/Formatter.h similarity index 89% rename from qt/formatter.h rename to qt/Formatter.h index e8982def8..970d61e8e 100644 --- a/qt/formatter.h +++ b/qt/Formatter.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2012-2014 Mnemosyne LLC + * This file Copyright (C) 2012-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,15 +7,15 @@ * $Id$ */ -#ifndef QTR_UNITS -#define QTR_UNITS +#ifndef QTR_FORMATTER_H +#define QTR_FORMATTER_H + +#include // int64_t #include #include #include -#include // int64_t - class Speed; class Formatter: public QObject @@ -50,4 +50,4 @@ class Formatter: public QObject static QString unitStrings[3][5]; }; -#endif +#endif // QTR_FORMATTER_H diff --git a/qt/freespace-label.cc b/qt/FreeSpaceLabel.cc similarity index 83% rename from qt/freespace-label.cc rename to qt/FreeSpaceLabel.cc index aa76b0212..70784d6b2 100644 --- a/qt/freespace-label.cc +++ b/qt/FreeSpaceLabel.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2013-2014 Mnemosyne LLC + * This file Copyright (C) 2013-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -12,16 +12,16 @@ #include #include -#include "formatter.h" -#include "freespace-label.h" -#include "session.h" +#include "Formatter.h" +#include "FreeSpaceLabel.h" +#include "Session.h" namespace { static const int INTERVAL_MSEC = 15000; } -FreespaceLabel::FreespaceLabel (QWidget * parent): +FreeSpaceLabel::FreeSpaceLabel (QWidget * parent): QLabel (parent), mySession (nullptr), myTag (-1), @@ -34,7 +34,7 @@ FreespaceLabel::FreespaceLabel (QWidget * parent): } void -FreespaceLabel::setSession (Session& session) +FreeSpaceLabel::setSession (Session& session) { if (mySession == &session) return; @@ -51,7 +51,7 @@ FreespaceLabel::setSession (Session& session) } void -FreespaceLabel::setPath (const QString& path) +FreeSpaceLabel::setPath (const QString& path) { if (myPath != path) { @@ -62,7 +62,7 @@ FreespaceLabel::setPath (const QString& path) } void -FreespaceLabel::onTimer () +FreeSpaceLabel::onTimer () { myTimer.stop (); @@ -78,7 +78,7 @@ FreespaceLabel::onTimer () } void -FreespaceLabel::onSessionExecuted (int64_t tag, const QString& result, tr_variant * arguments) +FreeSpaceLabel::onSessionExecuted (int64_t tag, const QString& result, tr_variant * arguments) { Q_UNUSED (result); diff --git a/qt/freespace-label.h b/qt/FreeSpaceLabel.h similarity index 69% rename from qt/freespace-label.h rename to qt/FreeSpaceLabel.h index 536251111..4438685e3 100644 --- a/qt/freespace-label.h +++ b/qt/FreeSpaceLabel.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2013-2014 Mnemosyne LLC + * This file Copyright (C) 2013-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef QTR_FREESPACE_LABEL_H -#define QTR_FREESPACE_LABEL_H +#ifndef QTR_FREE_SPACE_LABEL_H +#define QTR_FREE_SPACE_LABEL_H #include @@ -23,13 +23,13 @@ extern "C" struct tr_variant; } -class FreespaceLabel: public QLabel +class FreeSpaceLabel: public QLabel { Q_OBJECT public: - FreespaceLabel (QWidget * parent = 0); - virtual ~FreespaceLabel () {} + FreeSpaceLabel (QWidget * parent = 0); + virtual ~FreeSpaceLabel () {} void setSession (Session& session); void setPath (const QString& folder); @@ -45,5 +45,4 @@ class FreespaceLabel: public QLabel void onTimer (); }; -#endif // QTR_FREESPACE_LABEL_H - +#endif // QTR_FREE_SPACE_LABEL_H diff --git a/qt/tricontoolbutton.cc b/qt/IconToolButton.cc similarity index 69% rename from qt/tricontoolbutton.cc rename to qt/IconToolButton.cc index 73642f69e..8c977253a 100644 --- a/qt/tricontoolbutton.cc +++ b/qt/IconToolButton.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -11,14 +11,14 @@ #include #include -#include "tricontoolbutton.h" +#include "IconToolButton.h" -TrIconToolButton::TrIconToolButton (QWidget * parent): +IconToolButton::IconToolButton (QWidget * parent): QToolButton (parent) { } -void TrIconToolButton::paintEvent (QPaintEvent * /*event*/) +void IconToolButton::paintEvent (QPaintEvent * /*event*/) { QStylePainter painter(this); QStyleOptionToolButton option; diff --git a/qt/tricontoolbutton.h b/qt/IconToolButton.h similarity index 70% rename from qt/tricontoolbutton.h rename to qt/IconToolButton.h index 714cadd88..40a360845 100644 --- a/qt/tricontoolbutton.h +++ b/qt/IconToolButton.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -12,12 +12,12 @@ #include -class TrIconToolButton: public QToolButton +class IconToolButton: public QToolButton { Q_OBJECT public: - TrIconToolButton (QWidget * parent = nullptr); + IconToolButton (QWidget * parent = nullptr); protected: virtual void paintEvent (QPaintEvent * event); diff --git a/qt/license.cc b/qt/LicenseDialog.cc similarity index 95% rename from qt/license.cc rename to qt/LicenseDialog.cc index 0ab186ce2..19305d464 100644 --- a/qt/license.cc +++ b/qt/LicenseDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -11,7 +11,7 @@ #include #include -#include "license.h" +#include "LicenseDialog.h" LicenseDialog::LicenseDialog (QWidget * parent): QDialog (parent, Qt::Dialog) diff --git a/qt/license.h b/qt/LicenseDialog.h similarity index 66% rename from qt/license.h rename to qt/LicenseDialog.h index a51a8d573..921e3edfd 100644 --- a/qt/license.h +++ b/qt/LicenseDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef LICENSE_DIALOG_H -#define LICENSE_DIALOG_H +#ifndef QTR_LICENSE_DIALOG_H +#define QTR_LICENSE_DIALOG_H #include @@ -21,5 +21,4 @@ class LicenseDialog: public QDialog ~LicenseDialog () {} }; -#endif - +#endif // QTR_LICENSE_DIALOG_H diff --git a/qt/mainwin.cc b/qt/MainWindow.cc similarity index 90% rename from qt/mainwin.cc rename to qt/MainWindow.cc index 9b7fb5318..a47a4f183 100644 --- a/qt/mainwin.cc +++ b/qt/MainWindow.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -21,28 +21,27 @@ #include #include -#include "about.h" -#include "add-data.h" -#include "app.h" -#include "details.h" -#include "filterbar.h" -#include "filters.h" -#include "formatter.h" -#include "hig.h" -#include "mainwin.h" -#include "make-dialog.h" -#include "options.h" -#include "prefs.h" -#include "prefs-dialog.h" -#include "relocate.h" -#include "session.h" -#include "session-dialog.h" -#include "speed.h" -#include "stats-dialog.h" -#include "torrent-delegate.h" -#include "torrent-delegate-min.h" -#include "torrent-filter.h" -#include "torrent-model.h" +#include "AboutDialog.h" +#include "AddData.h" +#include "Application.h" +#include "DetailsDialog.h" +#include "FilterBar.h" +#include "Filters.h" +#include "Formatter.h" +#include "MainWindow.h" +#include "MakeDialog.h" +#include "OptionsDialog.h" +#include "Prefs.h" +#include "PrefsDialog.h" +#include "RelocateDialog.h" +#include "Session.h" +#include "SessionDialog.h" +#include "Speed.h" +#include "StatsDialog.h" +#include "TorrentDelegate.h" +#include "TorrentDelegateMin.h" +#include "TorrentFilter.h" +#include "TorrentModel.h" #define PREFS_KEY "prefs-key"; @@ -69,7 +68,7 @@ class ListViewProxyStyle: public QProxyStyle QIcon -TrMainWindow::getStockIcon (const QString& name, int fallback) +MainWindow::getStockIcon (const QString& name, int fallback) { QIcon icon = QIcon::fromTheme (name); @@ -79,7 +78,7 @@ TrMainWindow::getStockIcon (const QString& name, int fallback) return icon; } -TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, bool minimized): +MainWindow::MainWindow (Session& session, Prefs& prefs, TorrentModel& model, bool minimized): myLastFullUpdateTime (0), mySessionDialog (new SessionDialog (session, prefs, this)), myPrefsDialog (), @@ -291,7 +290,7 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, refreshTitle (); } -TrMainWindow::~TrMainWindow () +MainWindow::~MainWindow () { } @@ -300,13 +299,13 @@ TrMainWindow::~TrMainWindow () ****/ void -TrMainWindow::onSessionSourceChanged () +MainWindow::onSessionSourceChanged () { myModel.clear (); } void -TrMainWindow::onModelReset () +MainWindow::onModelReset () { refreshTitle (); refreshActionSensitivitySoon (); @@ -321,7 +320,7 @@ TrMainWindow::onModelReset () #define PREF_VARIANTS_KEY "pref-variants-list" void -TrMainWindow::onSetPrefs () +MainWindow::onSetPrefs () { const QVariantList p = sender ()->property (PREF_VARIANTS_KEY).toList (); assert ( (p.size () % 2) == 0); @@ -330,7 +329,7 @@ TrMainWindow::onSetPrefs () } void -TrMainWindow::onSetPrefs (bool isChecked) +MainWindow::onSetPrefs (bool isChecked) { if (isChecked) onSetPrefs (); @@ -339,7 +338,7 @@ TrMainWindow::onSetPrefs (bool isChecked) #define SHOW_KEY "show-mode" void -TrMainWindow::initStatusBar () +MainWindow::initStatusBar () { ui.optionsButton->setMenu (createOptionsMenu ()); @@ -353,7 +352,7 @@ TrMainWindow::initStatusBar () } QMenu * -TrMainWindow::createOptionsMenu () +MainWindow::createOptionsMenu () { QMenu * menu; QMenu * sub; @@ -437,7 +436,7 @@ TrMainWindow::createOptionsMenu () } QMenu * -TrMainWindow::createStatsModeMenu () +MainWindow::createStatsModeMenu () { QActionGroup * a = new QActionGroup (this); a->addAction (ui.action_TotalRatio); @@ -464,22 +463,22 @@ TrMainWindow::createStatsModeMenu () ****/ void -TrMainWindow::setSortPref (int i) +MainWindow::setSortPref (int i) { myPrefs.set (Prefs::SORT_MODE, SortMode (i)); } -void TrMainWindow::onSortByActivityToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_ACTIVITY); } -void TrMainWindow::onSortByAgeToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_AGE); } -void TrMainWindow::onSortByETAToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_ETA); } -void TrMainWindow::onSortByNameToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_NAME); } -void TrMainWindow::onSortByProgressToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_PROGRESS); } -void TrMainWindow::onSortByQueueToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_QUEUE); } -void TrMainWindow::onSortByRatioToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_RATIO); } -void TrMainWindow::onSortBySizeToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_SIZE); } -void TrMainWindow::onSortByStateToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_STATE); } +void MainWindow::onSortByActivityToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_ACTIVITY); } +void MainWindow::onSortByAgeToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_AGE); } +void MainWindow::onSortByETAToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_ETA); } +void MainWindow::onSortByNameToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_NAME); } +void MainWindow::onSortByProgressToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_PROGRESS); } +void MainWindow::onSortByQueueToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_QUEUE); } +void MainWindow::onSortByRatioToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_RATIO); } +void MainWindow::onSortBySizeToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_SIZE); } +void MainWindow::onSortByStateToggled (bool b) { if (b) setSortPref (SortMode::SORT_BY_STATE); } void -TrMainWindow::setSortAscendingPref (bool b) +MainWindow::setSortAscendingPref (bool b) { myPrefs.set (Prefs::SORT_REVERSED, b); } @@ -489,7 +488,7 @@ TrMainWindow::setSortAscendingPref (bool b) ****/ void -TrMainWindow::showEvent (QShowEvent * event) +MainWindow::showEvent (QShowEvent * event) { Q_UNUSED (event); @@ -501,7 +500,7 @@ TrMainWindow::showEvent (QShowEvent * event) ****/ void -TrMainWindow::hideEvent (QHideEvent * event) +MainWindow::hideEvent (QHideEvent * event) { Q_UNUSED (event); @@ -514,7 +513,7 @@ TrMainWindow::hideEvent (QHideEvent * event) ****/ void -TrMainWindow::openPreferences () +MainWindow::openPreferences () { if (myPrefsDialog.isNull ()) { @@ -530,17 +529,17 @@ TrMainWindow::openPreferences () } void -TrMainWindow::onDetailsDestroyed () +MainWindow::onDetailsDestroyed () { myDetailsDialog = 0; } void -TrMainWindow::openProperties () +MainWindow::openProperties () { if (myDetailsDialog == 0) { - myDetailsDialog = new Details (mySession, myPrefs, myModel, this); + myDetailsDialog = new DetailsDialog (mySession, myPrefs, myModel, this); connect (myDetailsDialog, SIGNAL (destroyed (QObject*)), this, SLOT (onDetailsDestroyed ())); } @@ -549,7 +548,7 @@ TrMainWindow::openProperties () } void -TrMainWindow::setLocation () +MainWindow::setLocation () { QDialog * d = new RelocateDialog (mySession, myModel, getSelectedTorrents (), this); d->setAttribute (Qt::WA_DeleteOnClose, true); @@ -588,7 +587,7 @@ void openSelect (const QString& path) #endif void -TrMainWindow::openFolder () +MainWindow::openFolder () { const int torrentId (*getSelectedTorrents ().begin ()); const Torrent * tor (myModel.getTorrentFromId (torrentId)); @@ -611,27 +610,27 @@ TrMainWindow::openFolder () } void -TrMainWindow::copyMagnetLinkToClipboard () +MainWindow::copyMagnetLinkToClipboard () { const int id (*getSelectedTorrents ().begin ()); mySession.copyMagnetLinkToClipboard (id); } void -TrMainWindow::openDonate () +MainWindow::openDonate () { QDesktopServices::openUrl (QUrl (QLatin1String ("http://www.transmissionbt.com/donate.php"))); } void -TrMainWindow::openHelp () +MainWindow::openHelp () { QDesktopServices::openUrl (QUrl (QString::fromLatin1 ("http://www.transmissionbt.com/help/gtk/%1.%2x"). arg (MAJOR_VERSION).arg (MINOR_VERSION / 10))); } void -TrMainWindow::refreshTitle () +MainWindow::refreshTitle () { QString title (QLatin1String ("Transmission")); const QUrl url (mySession.getRemoteUrl ()); @@ -643,7 +642,7 @@ TrMainWindow::refreshTitle () } void -TrMainWindow::refreshTrayIconSoon () +MainWindow::refreshTrayIconSoon () { if (!myRefreshTrayIconTimer.isActive ()) { @@ -652,7 +651,7 @@ TrMainWindow::refreshTrayIconSoon () } } void -TrMainWindow::refreshTrayIcon () +MainWindow::refreshTrayIcon () { Speed upSpeed, downSpeed; size_t upCount, downCount; @@ -683,7 +682,7 @@ TrMainWindow::refreshTrayIcon () } void -TrMainWindow::refreshStatusBar () +MainWindow::refreshStatusBar () { Speed upSpeed, downSpeed; size_t upCount, downCount; @@ -726,7 +725,7 @@ TrMainWindow::refreshStatusBar () void -TrMainWindow::refreshActionSensitivitySoon () +MainWindow::refreshActionSensitivitySoon () { if (!myRefreshActionSensitivityTimer.isActive ()) { @@ -735,7 +734,7 @@ TrMainWindow::refreshActionSensitivitySoon () } } void -TrMainWindow::refreshActionSensitivity () +MainWindow::refreshActionSensitivity () { int selected (0); int paused (0); @@ -801,13 +800,13 @@ TrMainWindow::refreshActionSensitivity () **/ void -TrMainWindow::clearSelection () +MainWindow::clearSelection () { ui.action_DeselectAll->trigger (); } QSet -TrMainWindow::getSelectedTorrents () const +MainWindow::getSelectedTorrents () const { QSet ids; @@ -821,67 +820,67 @@ TrMainWindow::getSelectedTorrents () const } void -TrMainWindow::startSelected () +MainWindow::startSelected () { mySession.startTorrents (getSelectedTorrents ()); } void -TrMainWindow::startSelectedNow () +MainWindow::startSelectedNow () { mySession.startTorrentsNow (getSelectedTorrents ()); } void -TrMainWindow::pauseSelected () +MainWindow::pauseSelected () { mySession.pauseTorrents (getSelectedTorrents ()); } void -TrMainWindow::queueMoveTop () +MainWindow::queueMoveTop () { mySession.queueMoveTop (getSelectedTorrents ()); } void -TrMainWindow::queueMoveUp () +MainWindow::queueMoveUp () { mySession.queueMoveUp (getSelectedTorrents ()); } void -TrMainWindow::queueMoveDown () +MainWindow::queueMoveDown () { mySession.queueMoveDown (getSelectedTorrents ()); } void -TrMainWindow::queueMoveBottom () +MainWindow::queueMoveBottom () { mySession.queueMoveBottom (getSelectedTorrents ()); } void -TrMainWindow::startAll () +MainWindow::startAll () { mySession.startTorrents (); } void -TrMainWindow::pauseAll () +MainWindow::pauseAll () { mySession.pauseTorrents (); } void -TrMainWindow::removeSelected () +MainWindow::removeSelected () { removeTorrents (false); } void -TrMainWindow::deleteSelected () +MainWindow::deleteSelected () { removeTorrents (true); } void -TrMainWindow::verifySelected () +MainWindow::verifySelected () { mySession.verifyTorrents (getSelectedTorrents ()); } void -TrMainWindow::reannounceSelected () +MainWindow::reannounceSelected () { mySession.reannounceTorrents (getSelectedTorrents ()); } @@ -890,39 +889,39 @@ TrMainWindow::reannounceSelected () *** **/ -void TrMainWindow::showTotalRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("total-ratio")); } -void TrMainWindow::showTotalTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("total-transfer")); } -void TrMainWindow::showSessionRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("session-ratio")); } -void TrMainWindow::showSessionTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("session-transfer")); } +void MainWindow::showTotalRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("total-ratio")); } +void MainWindow::showTotalTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("total-transfer")); } +void MainWindow::showSessionRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("session-ratio")); } +void MainWindow::showSessionTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("session-transfer")); } /** *** **/ void -TrMainWindow::setCompactView (bool visible) +MainWindow::setCompactView (bool visible) { myPrefs.set (Prefs::COMPACT_VIEW, visible); } void -TrMainWindow::toggleSpeedMode () +MainWindow::toggleSpeedMode () { myPrefs.toggleBool (Prefs::ALT_SPEED_LIMIT_ENABLED); const bool mode = myPrefs.get (Prefs::ALT_SPEED_LIMIT_ENABLED); myAltSpeedAction->setChecked (mode); } void -TrMainWindow::setToolbarVisible (bool visible) +MainWindow::setToolbarVisible (bool visible) { myPrefs.set (Prefs::TOOLBAR, visible); } void -TrMainWindow::setFilterbarVisible (bool visible) +MainWindow::setFilterbarVisible (bool visible) { myPrefs.set (Prefs::FILTERBAR, visible); } void -TrMainWindow::setStatusbarVisible (bool visible) +MainWindow::setStatusbarVisible (bool visible) { myPrefs.set (Prefs::STATUSBAR, visible); } @@ -932,7 +931,7 @@ TrMainWindow::setStatusbarVisible (bool visible) **/ void -TrMainWindow::toggleWindows (bool doShow) +MainWindow::toggleWindows (bool doShow) { if (!doShow) { @@ -949,7 +948,7 @@ TrMainWindow::toggleWindows (bool doShow) } void -TrMainWindow::trayActivated (QSystemTrayIcon::ActivationReason reason) +MainWindow::trayActivated (QSystemTrayIcon::ActivationReason reason) { if ((reason == QSystemTrayIcon::Trigger) || (reason == QSystemTrayIcon::DoubleClick)) @@ -963,7 +962,7 @@ TrMainWindow::trayActivated (QSystemTrayIcon::ActivationReason reason) void -TrMainWindow::refreshPref (int key) +MainWindow::refreshPref (int key) { bool b; int i; @@ -1106,7 +1105,7 @@ namespace } void -TrMainWindow::newTorrent () +MainWindow::newTorrent () { MakeDialog * dialog = new MakeDialog (mySession, this); dialog->setAttribute (Qt::WA_DeleteOnClose); @@ -1114,7 +1113,7 @@ TrMainWindow::newTorrent () } void -TrMainWindow::openTorrent () +MainWindow::openTorrent () { QFileDialog * d; d = new QFileDialog (this, @@ -1142,7 +1141,7 @@ TrMainWindow::openTorrent () } void -TrMainWindow::openURL () +MainWindow::openURL () { QString str = qApp->clipboard ()->text (QClipboard::Selection); @@ -1156,7 +1155,7 @@ TrMainWindow::openURL () } void -TrMainWindow::addTorrents (const QStringList& filenames) +MainWindow::addTorrents (const QStringList& filenames) { bool showOptions = myPrefs.getBool (Prefs::OPTIONS_PROMPT); @@ -1173,7 +1172,7 @@ TrMainWindow::addTorrents (const QStringList& filenames) } void -TrMainWindow::addTorrent (const AddData& addMe, bool showOptions) +MainWindow::addTorrent (const AddData& addMe, bool showOptions) { if (showOptions) { @@ -1189,7 +1188,7 @@ TrMainWindow::addTorrent (const AddData& addMe, bool showOptions) } void -TrMainWindow::removeTorrents (const bool deleteFiles) +MainWindow::removeTorrents (const bool deleteFiles) { QSet ids; QMessageBox msgBox (this); @@ -1296,7 +1295,7 @@ TrMainWindow::removeTorrents (const bool deleteFiles) ***/ void -TrMainWindow::updateNetworkIcon () +MainWindow::updateNetworkIcon () { const time_t now = time (NULL); const int period = 3; @@ -1337,26 +1336,26 @@ TrMainWindow::updateNetworkIcon () } void -TrMainWindow::onNetworkTimer () +MainWindow::onNetworkTimer () { updateNetworkIcon (); } void -TrMainWindow::dataReadProgress () +MainWindow::dataReadProgress () { if (!myNetworkError) myLastReadTime = time (NULL); } void -TrMainWindow::dataSendProgress () +MainWindow::dataSendProgress () { myLastSendTime = time (NULL); } void -TrMainWindow::onError (QNetworkReply::NetworkError code) +MainWindow::onError (QNetworkReply::NetworkError code) { const bool hadError = myNetworkError; const bool haveError = (code != QNetworkReply::NoError) @@ -1373,13 +1372,13 @@ TrMainWindow::onError (QNetworkReply::NetworkError code) } void -TrMainWindow::errorMessage (const QString& msg) +MainWindow::errorMessage (const QString& msg) { myErrorMessage = msg; } void -TrMainWindow::wrongAuthentication () +MainWindow::wrongAuthentication () { mySession.stop (); mySessionDialog->show (); @@ -1390,7 +1389,7 @@ TrMainWindow::wrongAuthentication () ***/ void -TrMainWindow::dragEnterEvent (QDragEnterEvent * event) +MainWindow::dragEnterEvent (QDragEnterEvent * event) { const QMimeData * mime = event->mimeData (); @@ -1402,7 +1401,7 @@ TrMainWindow::dragEnterEvent (QDragEnterEvent * event) } void -TrMainWindow::dropEvent (QDropEvent * event) +MainWindow::dropEvent (QDropEvent * event) { QStringList list; @@ -1437,7 +1436,7 @@ TrMainWindow::dropEvent (QDropEvent * event) ***/ void -TrMainWindow::contextMenuEvent (QContextMenuEvent * event) +MainWindow::contextMenuEvent (QContextMenuEvent * event) { QMenu * menu = new QMenu (this); diff --git a/qt/mainwin.h b/qt/MainWindow.h similarity index 91% rename from qt/mainwin.h rename to qt/MainWindow.h index 01d7b4af5..33c1d40f8 100644 --- a/qt/mainwin.h +++ b/qt/MainWindow.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef MAIN_WINDOW_H -#define MAIN_WINDOW_H +#ifndef QTR_MAIN_WINDOW_H +#define QTR_MAIN_WINDOW_H #include #include @@ -23,19 +23,14 @@ #include #include -extern "C" -{ - struct tr_variant; -} - -#include "filters.h" -#include "torrent-filter.h" -#include "ui_mainwin.h" +#include "Filters.h" +#include "TorrentFilter.h" +#include "ui_MainWindow.h" class AddData; class ActionDelegator; class Prefs; -class Details; +class DetailsDialog; class Session; class TorrentDelegate; class TorrentDelegateMin; @@ -47,7 +42,12 @@ class QModelIndex; class QSortFilterProxyModel; class Filterbar; -class TrMainWindow: public QMainWindow +extern "C" +{ + struct tr_variant; +} + +class MainWindow: public QMainWindow { Q_OBJECT @@ -61,7 +61,7 @@ class TrMainWindow: public QMainWindow QPointer myPrefsDialog; QDialog * myAboutDialog; QDialog * myStatsDialog; - Details * myDetailsDialog; + DetailsDialog * myDetailsDialog; QSystemTrayIcon myTrayIcon; TorrentFilter myFilterModel; TorrentDelegate * myTorrentDelegate; @@ -180,8 +180,8 @@ class TrMainWindow: public QMainWindow void wrongAuthentication (); public: - TrMainWindow (Session&, Prefs&, TorrentModel&, bool minized); - virtual ~TrMainWindow (); + MainWindow (Session&, Prefs&, TorrentModel&, bool minized); + virtual ~MainWindow (); protected: virtual void contextMenuEvent (QContextMenuEvent *); @@ -189,4 +189,4 @@ class TrMainWindow: public QMainWindow virtual void dropEvent (QDropEvent *); }; -#endif +#endif // QTR_MAIN_WINDOW_H diff --git a/qt/mainwin.ui b/qt/MainWindow.ui similarity index 99% rename from qt/mainwin.ui rename to qt/MainWindow.ui index 42904288f..fa7b75e8c 100644 --- a/qt/mainwin.ui +++ b/qt/MainWindow.ui @@ -62,7 +62,7 @@ 3 - + :/icons/utilities.png:/icons/utilities.png @@ -130,7 +130,7 @@ - + :/icons/ratio.png:/icons/ratio.png @@ -757,9 +757,9 @@ - TrIconToolButton + IconToolButton QToolButton -
tricontoolbutton.h
+
IconToolButton.h
diff --git a/qt/make-dialog.cc b/qt/MakeDialog.cc similarity index 94% rename from qt/make-dialog.cc rename to qt/MakeDialog.cc index ca3765614..7c5be0020 100644 --- a/qt/make-dialog.cc +++ b/qt/MakeDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -17,13 +17,13 @@ #include #include -#include "column-resizer.h" -#include "formatter.h" -#include "make-dialog.h" -#include "session.h" -#include "utils.h" +#include "ColumnResizer.h" +#include "Formatter.h" +#include "MakeDialog.h" +#include "Session.h" +#include "Utils.h" -#include "ui_make-progress-dialog.h" +#include "ui_MakeProgressDialog.h" namespace { @@ -117,7 +117,7 @@ MakeProgressDialog::onProgress () ui.dialogButtons->button (QDialogButtonBox::Open)->setEnabled (b.isDone && b.result == TR_MAKEMETA_OK); } -#include "make-dialog.moc" +#include "MakeDialog.moc" /*** **** @@ -221,11 +221,11 @@ MakeDialog::MakeDialog (Session& session, QWidget * parent): { ui.setupUi (this); - ui.destinationButton->setMode (TrPathButton::DirectoryMode); + ui.destinationButton->setMode (PathButton::DirectoryMode); ui.destinationButton->setPath (QDir::homePath ()); - ui.sourceFolderButton->setMode (TrPathButton::DirectoryMode); - ui.sourceFileButton->setMode (TrPathButton::FileMode); + ui.sourceFolderButton->setMode (PathButton::DirectoryMode); + ui.sourceFileButton->setMode (PathButton::FileMode); ColumnResizer * cr (new ColumnResizer (this)); cr->addLayout (ui.filesSectionLayout); diff --git a/qt/make-dialog.h b/qt/MakeDialog.h similarity index 82% rename from qt/make-dialog.h rename to qt/MakeDialog.h index 8cb5f8e5f..5737f88ee 100644 --- a/qt/make-dialog.h +++ b/qt/MakeDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,14 +7,14 @@ * $Id$ */ -#ifndef MAKE_DIALOG_H -#define MAKE_DIALOG_H +#ifndef QTR_MAKE_DIALOG_H +#define QTR_MAKE_DIALOG_H #include #include -#include "ui_make-dialog.h" +#include "ui_MakeDialog.h" class QAbstractButton; @@ -50,4 +50,4 @@ class MakeDialog: public QDialog virtual ~MakeDialog (); }; -#endif +#endif // QTR_MAKE_DIALOG_H diff --git a/qt/make-dialog.ui b/qt/MakeDialog.ui similarity index 96% rename from qt/make-dialog.ui rename to qt/MakeDialog.ui index 1a520a422..aad69e15d 100644 --- a/qt/make-dialog.ui +++ b/qt/MakeDialog.ui @@ -43,7 +43,7 @@
- + @@ -53,7 +53,7 @@ - + false @@ -70,7 +70,7 @@ - + @@ -180,9 +180,9 @@ To add another primary URL, add it after a blank line. - TrPathButton + PathButton QToolButton -
path-button.h
+
PathButton.h
diff --git a/qt/make-progress-dialog.ui b/qt/MakeProgressDialog.ui similarity index 100% rename from qt/make-progress-dialog.ui rename to qt/MakeProgressDialog.ui diff --git a/qt/options.cc b/qt/OptionsDialog.cc similarity index 96% rename from qt/options.cc rename to qt/OptionsDialog.cc index 619c057ab..3cc466b6b 100644 --- a/qt/options.cc +++ b/qt/OptionsDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -14,14 +14,13 @@ #include /* mime64 */ #include -#include "add-data.h" -#include "file-tree.h" -#include "freespace-label.h" -#include "options.h" -#include "prefs.h" -#include "session.h" -#include "torrent.h" -#include "utils.h" +#include "AddData.h" +#include "FreeSpaceLabel.h" +#include "OptionsDialog.h" +#include "Prefs.h" +#include "Session.h" +#include "Torrent.h" +#include "Utils.h" /*** **** @@ -53,7 +52,7 @@ OptionsDialog::OptionsDialog (Session& session, const Prefs& prefs, const AddDat if (myAdd.type == AddData::FILENAME) { ui.sourceStack->setCurrentWidget (ui.sourceButton); - ui.sourceButton->setMode (TrPathButton::FileMode); + ui.sourceButton->setMode (PathButton::FileMode); ui.sourceButton->setTitle (tr ("Open Torrent")); ui.sourceButton->setNameFilter (tr ("Torrent Files (*.torrent);;All Files (*.*)")); ui.sourceButton->setPath (myAdd.filename); @@ -81,7 +80,7 @@ OptionsDialog::OptionsDialog (Session& session, const Prefs& prefs, const AddDat if (session.isLocal ()) { ui.destinationStack->setCurrentWidget (ui.destinationButton); - ui.destinationButton->setMode (TrPathButton::DirectoryMode); + ui.destinationButton->setMode (PathButton::DirectoryMode); ui.destinationButton->setTitle (tr ("Select Destination")); ui.destinationButton->setPath (downloadDir); myLocalDestination = downloadDir; @@ -197,7 +196,7 @@ OptionsDialog::reload () for (tr_file_index_t i = 0; i < myInfo.fileCount; ++i) { - TrFile file; + TorrentFile file; file.index = i; file.priority = myPriorities[i]; file.wanted = myWanted[i]; @@ -334,7 +333,7 @@ OptionsDialog::clearVerify () myVerifyPiecePos = 0; myVerifyTimer.stop (); - for (TrFile& f: myFiles) + for (TorrentFile& f: myFiles) f.have = 0; ui.filesView->update (myFiles); @@ -412,7 +411,7 @@ OptionsDialog::onTimeout () { for (auto i = myVerifyBins.begin (), end = myVerifyBins.end (); i != end; ++i) { - TrFile& f (myFiles[i.key ()]); + TorrentFile& f (myFiles[i.key ()]); f.have += i.value (); changedFiles.append (f); } @@ -432,7 +431,7 @@ OptionsDialog::onTimeout () if (done) { uint64_t have = 0; - for (const TrFile& f: myFiles) + for (const TorrentFile& f: myFiles) have += f.have; if (!have) // everything failed diff --git a/qt/options.h b/qt/OptionsDialog.h similarity index 86% rename from qt/options.h rename to qt/OptionsDialog.h index 9fcf44ceb..03529e4e0 100644 --- a/qt/options.h +++ b/qt/OptionsDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef OPTIONS_DIALOG_H -#define OPTIONS_DIALOG_H +#ifndef QTR_OPTIONS_DIALOG_H +#define QTR_OPTIONS_DIALOG_H #include #include @@ -20,10 +20,10 @@ #include #include -#include "add-data.h" // AddData -#include "file-tree.h" // FileList +#include "AddData.h" // AddData +#include "Torrent.h" // FileList -#include "ui_options.h" +#include "ui_OptionsDialog.h" class Prefs; class Session; @@ -83,4 +83,4 @@ class OptionsDialog: public QDialog QTimer myEditTimer; }; -#endif +#endif // QTR_OPTIONS_DIALOG_H diff --git a/qt/options.ui b/qt/OptionsDialog.ui similarity index 91% rename from qt/options.ui rename to qt/OptionsDialog.ui index 03b88bd13..6eb542fee 100644 --- a/qt/options.ui +++ b/qt/OptionsDialog.ui @@ -29,7 +29,7 @@ 0 - +
@@ -51,12 +51,12 @@ 0 - + - + ... @@ -111,17 +111,17 @@ FileTreeView QTreeView -
file-tree.h
+
FileTreeView.h
- FreespaceLabel + FreeSpaceLabel QLabel -
freespace-label.h
+
FreeSpaceLabel.h
- TrPathButton + PathButton QToolButton -
path-button.h
+
PathButton.h
diff --git a/qt/path-button.cc b/qt/PathButton.cc similarity index 85% rename from qt/path-button.cc rename to qt/PathButton.cc index 634ff81e6..25779f385 100644 --- a/qt/path-button.cc +++ b/qt/PathButton.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2014 Mnemosyne LLC + * This file Copyright (C) 2014-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -16,10 +16,10 @@ #include #include -#include "path-button.h" -#include "utils.h" +#include "PathButton.h" +#include "Utils.h" -TrPathButton::TrPathButton (QWidget * parent): +PathButton::PathButton (QWidget * parent): QToolButton (parent), myMode (DirectoryMode), myTitle (), @@ -36,7 +36,7 @@ TrPathButton::TrPathButton (QWidget * parent): } void -TrPathButton::setMode (Mode mode) +PathButton::setMode (Mode mode) { if (myMode == mode) return; @@ -47,19 +47,19 @@ TrPathButton::setMode (Mode mode) } void -TrPathButton::setTitle (const QString& title) +PathButton::setTitle (const QString& title) { myTitle = title; } void -TrPathButton::setNameFilter (const QString& nameFilter) +PathButton::setNameFilter (const QString& nameFilter) { myNameFilter = nameFilter; } void -TrPathButton::setPath (const QString& path) +PathButton::setPath (const QString& path) { if (myPath == path) return; @@ -72,20 +72,20 @@ TrPathButton::setPath (const QString& path) } const QString& -TrPathButton::path () const +PathButton::path () const { return myPath; } QSize -TrPathButton::sizeHint () const +PathButton::sizeHint () const { const QSize sh (QToolButton::sizeHint ()); return QSize (qMin (sh.width (), 150), sh.height ()); } void -TrPathButton::paintEvent (QPaintEvent * /*event*/) +PathButton::paintEvent (QPaintEvent * /*event*/) { QStylePainter painter(this); QStyleOptionToolButton option; @@ -107,7 +107,7 @@ TrPathButton::paintEvent (QPaintEvent * /*event*/) } void -TrPathButton::onClicked () +PathButton::onClicked () { QFileDialog * dialog = new QFileDialog (window (), effectiveTitle ()); dialog->setFileMode (isDirMode () ? QFileDialog::Directory : QFileDialog::ExistingFile); @@ -137,14 +137,14 @@ TrPathButton::onClicked () } void -TrPathButton::onFileSelected (const QString& path) +PathButton::onFileSelected (const QString& path) { if (!path.isEmpty ()) setPath (path); } void -TrPathButton::updateAppearance () +PathButton::updateAppearance () { const QFileInfo pathInfo (myPath); @@ -165,13 +165,13 @@ TrPathButton::updateAppearance () } bool -TrPathButton::isDirMode () const +PathButton::isDirMode () const { return myMode == DirectoryMode; } QString -TrPathButton::effectiveTitle () const +PathButton::effectiveTitle () const { if (!myTitle.isEmpty ()) return myTitle; diff --git a/qt/path-button.h b/qt/PathButton.h similarity index 88% rename from qt/path-button.h rename to qt/PathButton.h index 393fc43f8..2f84d387e 100644 --- a/qt/path-button.h +++ b/qt/PathButton.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2014 Mnemosyne LLC + * This file Copyright (C) 2014-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -12,7 +12,7 @@ #include -class TrPathButton: public QToolButton +class PathButton: public QToolButton { Q_OBJECT @@ -24,7 +24,7 @@ class TrPathButton: public QToolButton }; public: - TrPathButton (QWidget * parent = nullptr); + PathButton (QWidget * parent = nullptr); void setMode (Mode mode); void setTitle (const QString& title); diff --git a/qt/prefs.cc b/qt/Prefs.cc similarity index 96% rename from qt/prefs.cc rename to qt/Prefs.cc index 818327c0b..70d8fb29f 100644 --- a/qt/prefs.cc +++ b/qt/Prefs.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,6 +7,8 @@ * $Id$ */ +#include + #include #include @@ -16,10 +18,10 @@ #include #include #include -#include -#include "prefs.h" -#include "types.h" -#include "utils.h" + +#include "CustomVariantType.h" +#include "Prefs.h" +#include "Utils.h" /*** **** @@ -38,7 +40,7 @@ Prefs::PrefItem Prefs::myItems[] = { SHOW_NOTIFICATION_ON_ADD, TR_KEY_torrent_added_notification_enabled, QVariant::Bool }, { SHOW_NOTIFICATION_ON_COMPLETE, TR_KEY_torrent_complete_notification_enabled, QVariant::Bool }, { ASKQUIT, TR_KEY_prompt_before_exit, QVariant::Bool }, - { SORT_MODE, TR_KEY_sort_mode, TrTypes::SortModeType }, + { SORT_MODE, TR_KEY_sort_mode, CustomVariantType::SortModeType }, { SORT_REVERSED, TR_KEY_sort_reversed, QVariant::Bool }, { COMPACT_VIEW, TR_KEY_compact_view, QVariant::Bool }, { FILTERBAR, TR_KEY_show_filterbar, QVariant::Bool }, @@ -54,7 +56,7 @@ Prefs::PrefItem Prefs::myItems[] = { MAIN_WINDOW_WIDTH, TR_KEY_main_window_width, QVariant::Int }, { MAIN_WINDOW_X, TR_KEY_main_window_x, QVariant::Int }, { MAIN_WINDOW_Y, TR_KEY_main_window_y, QVariant::Int }, - { FILTER_MODE, TR_KEY_filter_mode, TrTypes::FilterModeType }, + { FILTER_MODE, TR_KEY_filter_mode, CustomVariantType::FilterModeType }, { FILTER_TRACKERS, TR_KEY_filter_trackers, QVariant::String }, { FILTER_TEXT, TR_KEY_filter_text, QVariant::String }, { SESSION_IS_REMOTE, TR_KEY_remote_session_enabled, QVariant::Bool }, @@ -160,12 +162,12 @@ Prefs::Prefs (const QString& configDir): myValues[i].setValue (static_cast (intVal)); break; - case TrTypes::SortModeType: + case CustomVariantType::SortModeType: if (tr_variantGetStr (b, &str, NULL)) myValues[i] = QVariant::fromValue (SortMode (QString::fromUtf8 (str))); break; - case TrTypes::FilterModeType: + case CustomVariantType::FilterModeType: if (tr_variantGetStr (b, &str, NULL)) myValues[i] = QVariant::fromValue (FilterMode (QString::fromUtf8 (str))); break; @@ -218,11 +220,11 @@ Prefs::~Prefs () tr_variantDictAddInt (¤t_settings, key, val.toInt()); break; - case TrTypes::SortModeType: + case CustomVariantType::SortModeType: tr_variantDictAddStr (¤t_settings, key, val.value().name().toUtf8().constData()); break; - case TrTypes::FilterModeType: + case CustomVariantType::FilterModeType: tr_variantDictAddStr (¤t_settings, key, val.value().name().toUtf8().constData()); break; diff --git a/qt/prefs.h b/qt/Prefs.h similarity index 97% rename from qt/prefs.h rename to qt/Prefs.h index bc66eba31..c3291228b 100644 --- a/qt/prefs.h +++ b/qt/Prefs.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -16,10 +16,10 @@ #include #include -#include "filters.h" - #include +#include "Filters.h" + extern "C" { struct tr_variant; @@ -186,4 +186,4 @@ class Prefs: public QObject void changed (int key); }; -#endif +#endif // QTR_PREFS_H diff --git a/qt/prefs-dialog.cc b/qt/PrefsDialog.cc similarity index 96% rename from qt/prefs-dialog.cc rename to qt/PrefsDialog.cc index 2a7f3f122..e9d286e75 100644 --- a/qt/prefs-dialog.cc +++ b/qt/PrefsDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -33,14 +33,13 @@ #include #include -#include "column-resizer.h" -#include "freespace-label.h" -#include "formatter.h" -#include "hig.h" -#include "prefs.h" -#include "prefs-dialog.h" -#include "session.h" -#include "utils.h" +#include "ColumnResizer.h" +#include "FreeSpaceLabel.h" +#include "Formatter.h" +#include "Prefs.h" +#include "PrefsDialog.h" +#include "Session.h" +#include "Utils.h" /*** **** @@ -126,7 +125,7 @@ PrefsDialog::updateWidgetValue (QWidget * widget, int prefKey) w->setTime (QTime (0, 0).addSecs (myPrefs.getInt(prefKey) * 60)); else if (auto w = qobject_cast (widget)) w->setText (myPrefs.getString (prefKey)); - else if (auto w = qobject_cast (widget)) + else if (auto w = qobject_cast (widget)) w->setPath (myPrefs.getString (prefKey)); else return false; @@ -147,7 +146,7 @@ PrefsDialog::linkWidgetToPref (QWidget * widget, int prefKey) connect (widget, SIGNAL (editingFinished ()), SLOT (timeEditingFinished ())); else if (widget->inherits ("QLineEdit")) connect (widget, SIGNAL (editingFinished ()), SLOT (lineEditingFinished ())); - else if (widget->inherits ("TrPathButton")) + else if (widget->inherits ("PathButton")) connect (widget, SIGNAL (pathChanged (QString)), SLOT (pathChanged (QString))); else if (widget->inherits ("QAbstractSpinBox")) connect (widget, SIGNAL (editingFinished ()), SLOT (spinBoxEditingFinished ())); @@ -192,7 +191,7 @@ PrefsDialog::lineEditingFinished () void PrefsDialog::pathChanged (const QString& path) { - if (auto b = qobject_cast (sender ())) + if (auto b = qobject_cast (sender ())) setPref(getPrefKey (b), path); } @@ -472,10 +471,10 @@ PrefsDialog::initDownloadingTab () ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirButton); ui.completionScriptStack->setCurrentWidget (ui.completionScriptButton); - ui.watchDirButton->setMode (TrPathButton::DirectoryMode); - ui.downloadDirButton->setMode (TrPathButton::DirectoryMode); - ui.incompleteDirButton->setMode (TrPathButton::DirectoryMode); - ui.completionScriptButton->setMode (TrPathButton::FileMode); + ui.watchDirButton->setMode (PathButton::DirectoryMode); + ui.downloadDirButton->setMode (PathButton::DirectoryMode); + ui.incompleteDirButton->setMode (PathButton::DirectoryMode); + ui.completionScriptButton->setMode (PathButton::FileMode); ui.watchDirButton->setTitle (tr ("Select Watch Directory")); ui.downloadDirButton->setTitle (tr ("Select Destination")); diff --git a/qt/prefs-dialog.h b/qt/PrefsDialog.h similarity index 91% rename from qt/prefs-dialog.h rename to qt/PrefsDialog.h index b2abf1054..8f6be8726 100644 --- a/qt/prefs-dialog.h +++ b/qt/PrefsDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,15 +7,15 @@ * $Id$ */ -#ifndef PREFS_DIALOG_H -#define PREFS_DIALOG_H +#ifndef QTR_PREFS_DIALOG_H +#define QTR_PREFS_DIALOG_H #include #include #include -#include "prefs.h" -#include "ui_prefs-dialog.h" +#include "Prefs.h" +#include "ui_PrefsDialog.h" class QAbstractButton; class QCheckBox; @@ -32,7 +32,7 @@ class QTimeEdit; class QVBoxLayout; class QWidget; -class FreespaceLabel; +class FreeSpaceLabel; class Prefs; class Session; @@ -101,4 +101,4 @@ class PrefsDialog: public QDialog QMessageBox * myBlocklistDialog; }; -#endif +#endif // QTR_PREFS_DIALOG_H diff --git a/qt/prefs-dialog.ui b/qt/PrefsDialog.ui similarity index 98% rename from qt/prefs-dialog.ui rename to qt/PrefsDialog.ui index c3c398370..3f0d1b6f3 100644 --- a/qt/prefs-dialog.ui +++ b/qt/PrefsDialog.ui @@ -291,7 +291,7 @@ 0 - +
@@ -331,12 +331,12 @@ 0 - + - + ... @@ -482,7 +482,7 @@ 0 - + @@ -504,7 +504,7 @@ 0 - + @@ -1229,14 +1229,14 @@ - TrPathButton + PathButton QToolButton -
path-button.h
+
PathButton.h
- FreespaceLabel + FreeSpaceLabel QLabel -
freespace-label.h
+
FreeSpaceLabel.h
diff --git a/qt/relocate.cc b/qt/RelocateDialog.cc similarity index 91% rename from qt/relocate.cc rename to qt/RelocateDialog.cc index c91d8e39a..3ab744794 100644 --- a/qt/relocate.cc +++ b/qt/RelocateDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -9,10 +9,10 @@ #include -#include "relocate.h" -#include "session.h" -#include "torrent.h" -#include "torrent-model.h" +#include "RelocateDialog.h" +#include "Session.h" +#include "Torrent.h" +#include "TorrentModel.h" bool RelocateDialog::myMoveFlag = true; @@ -61,7 +61,7 @@ RelocateDialog::RelocateDialog (Session & session, if (mySession.isServer ()) { ui.newLocationStack->setCurrentWidget (ui.newLocationButton); - ui.newLocationButton->setMode (TrPathButton::DirectoryMode); + ui.newLocationButton->setMode (PathButton::DirectoryMode); ui.newLocationButton->setTitle (tr ("Select Location")); ui.newLocationButton->setPath (path); } diff --git a/qt/relocate.h b/qt/RelocateDialog.h similarity index 78% rename from qt/relocate.h rename to qt/RelocateDialog.h index ec43e32bf..0f5701340 100644 --- a/qt/relocate.h +++ b/qt/RelocateDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,13 +7,13 @@ * $Id$ */ -#ifndef RELOCATE_DIALOG_H -#define RELOCATE_DIALOG_H +#ifndef QTR_RELOCATE_DIALOG_H +#define QTR_RELOCATE_DIALOG_H #include #include -#include "ui_relocate.h" +#include "ui_RelocateDialog.h" class Session; class TorrentModel; @@ -41,4 +41,4 @@ class RelocateDialog: public QDialog static bool myMoveFlag; }; -#endif +#endif // QTR_RELOCATE_DIALOG_H diff --git a/qt/relocate.ui b/qt/RelocateDialog.ui similarity index 94% rename from qt/relocate.ui rename to qt/RelocateDialog.ui index 5e133b954..b394aaca3 100644 --- a/qt/relocate.ui +++ b/qt/RelocateDialog.ui @@ -41,7 +41,7 @@ - + @@ -75,9 +75,9 @@
- TrPathButton + PathButton QToolButton -
path-button.h
+
PathButton.h
diff --git a/qt/rpc-client.cc b/qt/RpcClient.cc similarity index 98% rename from qt/rpc-client.cc rename to qt/RpcClient.cc index 180078843..dad99d5be 100644 --- a/qt/rpc-client.cc +++ b/qt/RpcClient.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2014 Mnemosyne LLC + * This file Copyright (C) 2014-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -22,7 +22,7 @@ #include // tr_free #include // LONG_VERSION_STRING -#include "rpc-client.h" +#include "RpcClient.h" // #define DEBUG_HTTP diff --git a/qt/rpc-client.h b/qt/RpcClient.h similarity index 92% rename from qt/rpc-client.h rename to qt/RpcClient.h index 317e3b22a..643e77c0f 100644 --- a/qt/rpc-client.h +++ b/qt/RpcClient.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2014 Mnemosyne LLC + * This file Copyright (C) 2014-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef TR_RPC_CLIENT_H -#define TR_RPC_CLIENT_H +#ifndef QTR_RPC_CLIENT_H +#define QTR_RPC_CLIENT_H #include #include @@ -74,4 +74,4 @@ class RpcClient: public QObject QNetworkAccessManager * myNAM; }; -#endif +#endif // QTR_RPC_CLIENT_H diff --git a/qt/session.cc b/qt/Session.cc similarity index 98% rename from qt/session.cc rename to qt/Session.cc index 56763f778..1e6e3cb60 100644 --- a/qt/session.cc +++ b/qt/Session.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -26,12 +26,12 @@ #include // tr_free #include -#include "add-data.h" -#include "prefs.h" -#include "session.h" -#include "session-dialog.h" -#include "torrent.h" -#include "utils.h" +#include "AddData.h" +#include "Prefs.h" +#include "Session.h" +#include "SessionDialog.h" +#include "Torrent.h" +#include "Utils.h" namespace { @@ -807,8 +807,8 @@ Session::updateInfo (tr_variant * d) myPrefs.set (i, val); break; } - case TrTypes::FilterModeType: - case TrTypes::SortModeType: + case CustomVariantType::FilterModeType: + case CustomVariantType::SortModeType: case QVariant::String: { const char * val; diff --git a/qt/session.h b/qt/Session.h similarity index 97% rename from qt/session.h rename to qt/Session.h index ce2f89998..9a29736b6 100644 --- a/qt/session.h +++ b/qt/Session.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#ifndef TR_APP_SESSION_H -#define TR_APP_SESSION_H +#ifndef QTR_SESSION_H +#define QTR_SESSION_H #include #include @@ -18,7 +18,7 @@ #include #include -#include "rpc-client.h" +#include "RpcClient.h" class AddData; class Prefs; @@ -166,4 +166,4 @@ class Session: public QObject RpcClient myRpc; }; -#endif +#endif // QTR_SESSION_H diff --git a/qt/session-dialog.cc b/qt/SessionDialog.cc similarity index 95% rename from qt/session-dialog.cc rename to qt/SessionDialog.cc index 308d738c7..8d19b694f 100644 --- a/qt/session-dialog.cc +++ b/qt/SessionDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,9 +7,9 @@ * $Id$ */ -#include "prefs.h" -#include "session.h" -#include "session-dialog.h" +#include "Prefs.h" +#include "Session.h" +#include "SessionDialog.h" /*** **** diff --git a/qt/session-dialog.h b/qt/SessionDialog.h similarity index 77% rename from qt/session-dialog.h rename to qt/SessionDialog.h index b266ccd07..b1e805032 100644 --- a/qt/session-dialog.h +++ b/qt/SessionDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,13 +7,13 @@ * $Id$ */ -#ifndef SESSION_DIALOG_H -#define SESSION_DIALOG_H +#ifndef QTR_SESSION_DIALOG_H +#define QTR_SESSION_DIALOG_H #include #include -#include "ui_session-dialog.h" +#include "ui_SessionDialog.h" class Prefs; class Session; @@ -38,4 +38,4 @@ class SessionDialog: public QDialog QWidgetList myAuthWidgets; }; -#endif +#endif // QTR_SESSION_DIALOG_H diff --git a/qt/session-dialog.ui b/qt/SessionDialog.ui similarity index 100% rename from qt/session-dialog.ui rename to qt/SessionDialog.ui diff --git a/qt/speed.h b/qt/Speed.h similarity index 88% rename from qt/speed.h rename to qt/Speed.h index 74de86629..7c7ae33b0 100644 --- a/qt/speed.h +++ b/qt/Speed.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -10,7 +10,7 @@ #ifndef QTR_SPEED_H #define QTR_SPEED_H -#include "formatter.h" +#include "Formatter.h" class Speed { @@ -31,4 +31,4 @@ class Speed bool operator< (const Speed& that) const { return _Bps < that._Bps; } }; -#endif +#endif // QTR_SPEED_H diff --git a/qt/squeezelabel.cc b/qt/SqueezeLabel.cc similarity index 99% rename from qt/squeezelabel.cc rename to qt/SqueezeLabel.cc index 06f246dcf..b73aa4042 100644 --- a/qt/squeezelabel.cc +++ b/qt/SqueezeLabel.cc @@ -43,7 +43,7 @@ #include #include -#include "squeezelabel.h" +#include "SqueezeLabel.h" SqueezeLabel::SqueezeLabel (const QString& text, QWidget * parent): QLabel (text, parent) diff --git a/qt/squeezelabel.h b/qt/SqueezeLabel.h similarity index 94% rename from qt/squeezelabel.h rename to qt/SqueezeLabel.h index c73ec6edf..5d5834e7f 100644 --- a/qt/squeezelabel.h +++ b/qt/SqueezeLabel.h @@ -39,12 +39,12 @@ ** ****************************************************************************/ -#ifndef SQUEEZELABEL_H -#define SQUEEZELABEL_H +#ifndef QTR_SQUEEZE_LABEL_H +#define QTR_SQUEEZE_LABEL_H #include -class SqueezeLabel : public QLabel +class SqueezeLabel: public QLabel { Q_OBJECT @@ -56,5 +56,4 @@ class SqueezeLabel : public QLabel void paintEvent (QPaintEvent* paintEvent); }; -#endif // SQUEEZELABEL_H - +#endif // QTR_SQUEEZE_LABEL_H diff --git a/qt/stats-dialog.cc b/qt/StatsDialog.cc similarity index 92% rename from qt/stats-dialog.cc rename to qt/StatsDialog.cc index 8463a55af..9e6e34e27 100644 --- a/qt/stats-dialog.cc +++ b/qt/StatsDialog.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -9,10 +9,10 @@ #include -#include "column-resizer.h" -#include "formatter.h" -#include "session.h" -#include "stats-dialog.h" +#include "ColumnResizer.h" +#include "Formatter.h" +#include "Session.h" +#include "StatsDialog.h" enum { diff --git a/qt/stats-dialog.h b/qt/StatsDialog.h similarity index 74% rename from qt/stats-dialog.h rename to qt/StatsDialog.h index 1d23836df..9032e4624 100644 --- a/qt/stats-dialog.h +++ b/qt/StatsDialog.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,12 +7,12 @@ * $Id$ */ -#ifndef STATS_DIALOG_H -#define STATS_DIALOG_H +#ifndef QTR_STATS_DIALOG_H +#define QTR_STATS_DIALOG_H #include -#include "ui_stats-dialog.h" +#include "ui_StatsDialog.h" class Session; class QTimer; @@ -35,4 +35,4 @@ class StatsDialog: public QDialog Ui::StatsDialog ui; }; -#endif +#endif // QTR_STATS_DIALOG_H diff --git a/qt/stats-dialog.ui b/qt/StatsDialog.ui similarity index 100% rename from qt/stats-dialog.ui rename to qt/StatsDialog.ui diff --git a/qt/torrent.cc b/qt/Torrent.cc similarity index 97% rename from qt/torrent.cc rename to qt/Torrent.cc index bc3463c69..b838b5b78 100644 --- a/qt/torrent.cc +++ b/qt/Torrent.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -23,11 +23,10 @@ #include /* tr_new0, tr_strdup */ #include -#include "app.h" -#include "prefs.h" -#include "torrent.h" -#include "utils.h" - +#include "Application.h" +#include "Prefs.h" +#include "Torrent.h" +#include "Utils.h" Torrent::Torrent (const Prefs& prefs, int id): magnetTorrent (false), @@ -87,7 +86,7 @@ Torrent::myProperties[] = { FAILED_EVER, TR_KEY_corruptEver, QVariant::ULongLong, STAT_EXTRA }, { TRACKERS, TR_KEY_trackers, QVariant::StringList, STAT }, { HOSTS, TR_KEY_NONE, QVariant::StringList, DERIVED }, - { TRACKERSTATS, TR_KEY_trackerStats, TrTypes::TrackerStatsList, STAT_EXTRA }, + { TRACKERSTATS, TR_KEY_trackerStats, CustomVariantType::TrackerStatsList, STAT_EXTRA }, { MIME_ICON, TR_KEY_NONE, QVariant::Icon, DERIVED }, { SEED_RATIO_LIMIT, TR_KEY_seedRatioLimit, QVariant::Double, STAT }, { SEED_RATIO_MODE, TR_KEY_seedRatioMode, QVariant::Int, STAT }, @@ -106,7 +105,7 @@ Torrent::myProperties[] = { COMMENT, TR_KEY_comment, QVariant::String, INFO }, { CREATOR, TR_KEY_creator, QVariant::String, INFO }, { MANUAL_ANNOUNCE_TIME, TR_KEY_manualAnnounceTime, QVariant::DateTime, STAT_EXTRA }, - { PEERS, TR_KEY_peers, TrTypes::PeerList, STAT_EXTRA }, + { PEERS, TR_KEY_peers, CustomVariantType::PeerList, STAT_EXTRA }, { BANDWIDTH_PRIORITY, TR_KEY_bandwidthPriority, QVariant::Int, STAT_EXTRA }, { QUEUE_POSITION, TR_KEY_queuePosition, QVariant::Int, STAT }, }; @@ -357,7 +356,7 @@ Torrent::getSeedRatio (double& ratio) const bool Torrent::hasFileSubstring (const QString& substr) const { - for (const TrFile& file: myFiles) + for (const TorrentFile& file: myFiles) if (file.filename.contains (substr, Qt::CaseInsensitive)) return true; @@ -531,7 +530,7 @@ Torrent::update (tr_variant * d) } case QVariant::StringList: - case TrTypes::PeerList: + case CustomVariantType::PeerList: // handled below break; @@ -555,7 +554,7 @@ Torrent::update (tr_variant * d) while ((child = tr_variantListChild (files, i))) { - TrFile file; + TorrentFile file; size_t len; file.index = i++; @@ -580,7 +579,7 @@ Torrent::update (tr_variant * d) int64_t intVal; bool boolVal; tr_variant * child = tr_variantListChild (files, i); - TrFile& file (myFiles[i]); + TorrentFile& file (myFiles[i]); if (tr_variantDictFindInt (child, TR_KEY_bytesCompleted, &intVal)) file.have = intVal; @@ -615,7 +614,7 @@ Torrent::update (tr_variant * d) QStringList hosts; for (const QString& tracker: list) { - const QString host = Favicons::getHost (QUrl (tracker)); + const QString host = FaviconCache::getHost (QUrl (tracker)); if (!host.isEmpty()) hosts.append (host); } diff --git a/qt/torrent.h b/qt/Torrent.h similarity index 97% rename from qt/torrent.h rename to qt/Torrent.h index 6e346e229..f7707594c 100644 --- a/qt/torrent.h +++ b/qt/Torrent.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -23,22 +23,22 @@ #include #include -#include "speed.h" -#include "types.h" +#include "CustomVariantType.h" +#include "Speed.h" #ifdef ERROR #undef ERROR #endif +class Prefs; +class QPixmap; +class QStyle; + extern "C" { struct tr_variant; } -class Prefs; -class QPixmap; -class QStyle; - struct Peer { bool clientIsChoked; @@ -96,9 +96,9 @@ typedef QList TrackerStatsList; Q_DECLARE_METATYPE(TrackerStat) Q_DECLARE_METATYPE(TrackerStatsList) -struct TrFile +struct TorrentFile { - TrFile(): wanted(true), index(-1), priority(0), size(0), have(0) {} + TorrentFile(): wanted(true), index(-1), priority(0), size(0), have(0) {} bool wanted; int index; @@ -108,8 +108,8 @@ struct TrFile uint64_t have; }; -typedef QList FileList; -Q_DECLARE_METATYPE(TrFile) +typedef QList FileList; +Q_DECLARE_METATYPE(TorrentFile) Q_DECLARE_METATYPE(FileList) @@ -347,5 +347,4 @@ class Torrent: public QObject Q_DECLARE_METATYPE(const Torrent*) -#endif - +#endif // QTR_TORRENT_H diff --git a/qt/torrent-delegate.cc b/qt/TorrentDelegate.cc similarity index 99% rename from qt/torrent-delegate.cc rename to qt/TorrentDelegate.cc index b29cc22d0..fd8010cb6 100644 --- a/qt/torrent-delegate.cc +++ b/qt/TorrentDelegate.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -20,11 +20,11 @@ #include #include -#include "formatter.h" -#include "torrent.h" -#include "torrent-delegate.h" -#include "torrent-model.h" -#include "utils.h" +#include "Formatter.h" +#include "Torrent.h" +#include "TorrentDelegate.h" +#include "TorrentModel.h" +#include "Utils.h" enum { diff --git a/qt/torrent-delegate.h b/qt/TorrentDelegate.h similarity index 94% rename from qt/torrent-delegate.h rename to qt/TorrentDelegate.h index 28d8c19ef..fd1525796 100644 --- a/qt/torrent-delegate.h +++ b/qt/TorrentDelegate.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -50,4 +50,4 @@ class TorrentDelegate: public QStyledItemDelegate void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; }; -#endif +#endif // QTR_TORRENT_DELEGATE_H diff --git a/qt/torrent-delegate-min.cc b/qt/TorrentDelegateMin.cc similarity index 98% rename from qt/torrent-delegate-min.cc rename to qt/TorrentDelegateMin.cc index 2c67ea10f..1e9426c1f 100644 --- a/qt/torrent-delegate-min.cc +++ b/qt/TorrentDelegateMin.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -23,10 +23,10 @@ #include #include -#include "torrent.h" -#include "torrent-delegate-min.h" -#include "torrent-model.h" -#include "utils.h" +#include "Torrent.h" +#include "TorrentDelegateMin.h" +#include "TorrentModel.h" +#include "Utils.h" enum { diff --git a/qt/torrent-delegate-min.h b/qt/TorrentDelegateMin.h similarity index 85% rename from qt/torrent-delegate-min.h rename to qt/TorrentDelegateMin.h index 0ee40ff48..7f3d247fd 100644 --- a/qt/torrent-delegate-min.h +++ b/qt/TorrentDelegateMin.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -11,7 +11,8 @@ #define QTR_TORRENT_DELEGATE_MIN_H #include -#include "torrent-delegate.h" + +#include "TorrentDelegate.h" class QStyleOptionViewItem; class QStyle; @@ -31,4 +32,4 @@ class TorrentDelegateMin: public TorrentDelegate virtual ~TorrentDelegateMin () {} }; -#endif +#endif // QTR_TORRENT_DELEGATE_MIN_H diff --git a/qt/torrent-filter.cc b/qt/TorrentFilter.cc similarity index 96% rename from qt/torrent-filter.cc rename to qt/TorrentFilter.cc index 53c568554..019b3e376 100644 --- a/qt/torrent-filter.cc +++ b/qt/TorrentFilter.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -10,13 +10,12 @@ #include #include -#include "filters.h" -#include "hig.h" -#include "prefs.h" -#include "torrent.h" -#include "torrent-filter.h" -#include "torrent-model.h" -#include "utils.h" +#include "Filters.h" +#include "Prefs.h" +#include "Torrent.h" +#include "TorrentFilter.h" +#include "TorrentModel.h" +#include "Utils.h" TorrentFilter::TorrentFilter (const Prefs& prefs): myPrefs (prefs) diff --git a/qt/torrent-filter.h b/qt/TorrentFilter.h similarity index 93% rename from qt/torrent-filter.h rename to qt/TorrentFilter.h index a421a9b17..7b29d85fd 100644 --- a/qt/torrent-filter.h +++ b/qt/TorrentFilter.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -51,4 +51,4 @@ class TorrentFilter: public QSortFilterProxyModel const Prefs& myPrefs; }; -#endif +#endif // QTR_TORRENT_FILTER_H diff --git a/qt/torrent-model.cc b/qt/TorrentModel.cc similarity index 98% rename from qt/torrent-model.cc rename to qt/TorrentModel.cc index 1f5f9a931..f679ec654 100644 --- a/qt/torrent-model.cc +++ b/qt/TorrentModel.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -13,8 +13,8 @@ #include #include -#include "torrent-delegate.h" -#include "torrent-model.h" +#include "TorrentDelegate.h" +#include "TorrentModel.h" void TorrentModel::clear () diff --git a/qt/torrent-model.h b/qt/TorrentModel.h similarity index 93% rename from qt/torrent-model.h rename to qt/TorrentModel.h index 6a317480b..32493adf5 100644 --- a/qt/torrent-model.h +++ b/qt/TorrentModel.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -15,8 +15,8 @@ #include #include -#include "speed.h" -#include "torrent.h" +#include "Speed.h" +#include "Torrent.h" class Prefs; @@ -75,4 +75,4 @@ class TorrentModel: public QAbstractListModel virtual ~TorrentModel (); }; -#endif +#endif // QTR_TORRENT_MODEL_H diff --git a/qt/tracker-delegate.cc b/qt/TrackerDelegate.cc similarity index 97% rename from qt/tracker-delegate.cc rename to qt/TrackerDelegate.cc index 575e28778..b9edc42eb 100644 --- a/qt/tracker-delegate.cc +++ b/qt/TrackerDelegate.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -18,12 +18,12 @@ #include #include -#include "favicon.h" -#include "formatter.h" -#include "torrent.h" -#include "tracker-delegate.h" -#include "tracker-model.h" -#include "utils.h" +#include "FaviconCache.h" +#include "Formatter.h" +#include "Torrent.h" +#include "TrackerDelegate.h" +#include "TrackerModel.h" +#include "Utils.h" /*** **** @@ -62,7 +62,7 @@ namespace const QPoint& topLeft, int width) { const QStyle * style (qApp->style ()); - const QSize iconSize = Favicons::getIconSize (); + const QSize iconSize = FaviconCache::getIconSize (); QRect baseRect (topLeft, QSize (width, 0)); diff --git a/qt/tracker-delegate.h b/qt/TrackerDelegate.h similarity index 92% rename from qt/tracker-delegate.h rename to qt/TrackerDelegate.h index 3532cfa37..7c0c4693d 100644 --- a/qt/tracker-delegate.h +++ b/qt/TrackerDelegate.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -16,6 +16,7 @@ class QPainter; class QStyleOptionViewItem; class QStyle; + class Session; struct TrackerInfo; @@ -44,4 +45,4 @@ class TrackerDelegate: public QItemDelegate bool myShowMore; }; -#endif +#endif // QTR_TRACKER_DELEGATE_H diff --git a/qt/tracker-model.cc b/qt/TrackerModel.cc similarity index 97% rename from qt/tracker-model.cc rename to qt/TrackerModel.cc index 95d5b7fcd..7d5c918d8 100644 --- a/qt/tracker-model.cc +++ b/qt/TrackerModel.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -11,8 +11,8 @@ #include -#include "app.h" // MyApp -#include "tracker-model.h" +#include "Application.h" // Application +#include "TrackerModel.h" int TrackerModel::rowCount (const QModelIndex& parent) const diff --git a/qt/tracker-model.h b/qt/TrackerModel.h similarity index 87% rename from qt/tracker-model.h rename to qt/TrackerModel.h index a92ea915f..3be6bee24 100644 --- a/qt/tracker-model.h +++ b/qt/TrackerModel.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -14,8 +14,8 @@ #include #include -#include "torrent.h" -#include "torrent-model.h" +#include "Torrent.h" +#include "TorrentModel.h" struct TrackerInfo { @@ -45,4 +45,4 @@ class TrackerModel: public QAbstractListModel virtual ~TrackerModel () {} }; -#endif +#endif // QTR_TRACKER_MODEL_H diff --git a/qt/tracker-model-filter.cc b/qt/TrackerModelFilter.cc similarity index 86% rename from qt/tracker-model-filter.cc rename to qt/TrackerModelFilter.cc index 7557ff04a..b0621c835 100644 --- a/qt/tracker-model-filter.cc +++ b/qt/TrackerModelFilter.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,8 +7,8 @@ * $Id$ */ -#include "tracker-model.h" -#include "tracker-model-filter.h" +#include "TrackerModel.h" +#include "TrackerModelFilter.h" TrackerModelFilter::TrackerModelFilter (QObject * parent): QSortFilterProxyModel (parent), diff --git a/qt/tracker-model-filter.h b/qt/TrackerModelFilter.h similarity index 87% rename from qt/tracker-model-filter.h rename to qt/TrackerModelFilter.h index 825633870..0821062fd 100644 --- a/qt/tracker-model-filter.h +++ b/qt/TrackerModelFilter.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2010-2014 Mnemosyne LLC + * This file Copyright (C) 2010-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -30,4 +30,4 @@ class TrackerModelFilter : public QSortFilterProxyModel bool myShowBackups; }; -#endif +#endif // QTR_TRACKER_MODEL_FILTER_H diff --git a/qt/utils.cc b/qt/Utils.cc similarity index 96% rename from qt/utils.cc rename to qt/Utils.cc index 99c156988..582e80e74 100644 --- a/qt/utils.cc +++ b/qt/Utils.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -13,6 +13,7 @@ #endif #include +#include #include #include #include @@ -31,7 +32,7 @@ #include #include // tr_formatter -#include "utils.h" +#include "Utils.h" /*** **** @@ -201,3 +202,11 @@ Utils::removeTrailingDirSeparator (const QString& path) const QFileInfo pathInfo (path); return pathInfo.fileName ().isEmpty () ? pathInfo.absolutePath () : pathInfo.absoluteFilePath (); } + +QColor +Utils::getFadedColor (const QColor& color) +{ + QColor fadedColor (color); + fadedColor.setAlpha (128); + return fadedColor; +} diff --git a/qt/utils.h b/qt/Utils.h similarity index 87% rename from qt/utils.h rename to qt/Utils.h index 0b64a3549..ce2c63c97 100644 --- a/qt/utils.h +++ b/qt/Utils.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,17 +7,19 @@ * $Id$ */ -#ifndef QTR_UTILS -#define QTR_UTILS +#ifndef QTR_UTILS_H +#define QTR_UTILS_H + +#include // isxdigit() #include #include #include #include -#include // isxdigit() +#include "Speed.h" -#include "speed.h" +class QColor; class Utils: public QObject { @@ -41,6 +43,8 @@ class Utils: public QObject rect.adjust (dx1, 0, -dx2, 0); } + static QColor getFadedColor (const QColor& color); + /// /// URLs /// @@ -67,4 +71,4 @@ class Utils: public QObject } }; -#endif +#endif // QTR_UTILS_H diff --git a/qt/watchdir.cc b/qt/WatchDir.cc similarity index 96% rename from qt/watchdir.cc rename to qt/WatchDir.cc index 9da7d9cee..c7a48d6d1 100644 --- a/qt/watchdir.cc +++ b/qt/WatchDir.cc @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -15,9 +15,9 @@ #include -#include "prefs.h" -#include "torrent-model.h" -#include "watchdir.h" +#include "Prefs.h" +#include "TorrentModel.h" +#include "WatchDir.h" /*** **** diff --git a/qt/watchdir.h b/qt/WatchDir.h similarity index 86% rename from qt/watchdir.h rename to qt/WatchDir.h index 81dcc8afb..d94ce30cc 100644 --- a/qt/watchdir.h +++ b/qt/WatchDir.h @@ -1,5 +1,5 @@ /* - * This file Copyright (C) 2009-2014 Mnemosyne LLC + * This file Copyright (C) 2009-2015 Mnemosyne LLC * * It may be used under the GNU GPL versions 2 or 3 * or any future license endorsed by Mnemosyne LLC. @@ -7,16 +7,17 @@ * $Id$ */ -#ifndef QTR_WATCHDIR_H -#define QTR_WATCHDIR_H +#ifndef QTR_WATCH_DIR_H +#define QTR_WATCH_DIR_H #include #include #include -class TorrentModel; class QFileSystemWatcher; +class TorrentModel; + class WatchDir: public QObject { Q_OBJECT @@ -48,4 +49,4 @@ class WatchDir: public QObject QFileSystemWatcher * myWatcher; }; -#endif +#endif // QTR_WATCH_DIR_H diff --git a/qt/file-tree.cc b/qt/file-tree.cc deleted file mode 100644 index 74d93ccfe..000000000 --- a/qt/file-tree.cc +++ /dev/null @@ -1,1025 +0,0 @@ -/* - * This file Copyright (C) 2009-2014 Mnemosyne LLC - * - * It may be used under the GNU GPL versions 2 or 3 - * or any future license endorsed by Mnemosyne LLC. - * - * $Id$ - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include // priorities - -#include "file-tree.h" -#include "formatter.h" -#include "hig.h" -#include "torrent.h" // FileList -#include "utils.h" // mime icons - -enum -{ - COL_NAME, - FIRST_VISIBLE_COLUMN = COL_NAME, - COL_SIZE, - COL_PROGRESS, - COL_WANTED, - COL_PRIORITY, - LAST_VISIBLE_COLUMN = COL_PRIORITY, - - COL_FILE_INDEX, - NUM_COLUMNS -}; - -/**** -***** -****/ - -const QHash& -FileTreeItem::getMyChildRows () -{ - const size_t n = childCount(); - - // ensure that all the rows are hashed - while (myFirstUnhashedRow < n) - { - myChildRows.insert (myChildren[myFirstUnhashedRow]->name(), - myFirstUnhashedRow); - ++myFirstUnhashedRow; - } - - return myChildRows; -} - - -FileTreeItem::~FileTreeItem () -{ - assert(myChildren.isEmpty()); - - if (myParent != 0) - { - const int pos = row(); - assert ((pos>=0) && "couldn't find child in parent's lookup"); - myParent->myChildren.removeAt(pos); - myParent->myChildRows.remove(name()); - myParent->myFirstUnhashedRow = pos; - } -} - -void -FileTreeItem::appendChild (FileTreeItem * child) -{ - const size_t n = childCount(); - child->myParent = this; - myChildren.append (child); - myFirstUnhashedRow = n; -} - -FileTreeItem * -FileTreeItem::child (const QString& filename) -{ - FileTreeItem * item(0); - - const int row = getMyChildRows().value (filename, -1); - if (row != -1) - { - item = child (row); - assert (filename == item->name()); - } - - return item; -} - -int -FileTreeItem::row () const -{ - int i(-1); - - if(myParent) - { - i = myParent->getMyChildRows().value (name(), -1); - assert (this == myParent->myChildren[i]); - } - - return i; -} - -QVariant -FileTreeItem::data (int column, int role) const -{ - QVariant value; - - if (column == COL_FILE_INDEX) - { - value.setValue (myFileIndex); - } - else if (role == Qt::EditRole) - { - if (column == 0) - value.setValue (name()); - } - else if ((role == Qt::TextAlignmentRole) && column == COL_SIZE) - { - value = Qt::AlignRight + Qt::AlignVCenter; - } - else if (role == Qt::DisplayRole) - { - switch(column) - { - case COL_NAME: - value.setValue (name()); - break; - - case COL_SIZE: - value.setValue (sizeString() + QLatin1String (" ")); - break; - - case COL_PROGRESS: - value.setValue (progress()); - break; - - case COL_WANTED: - value.setValue (isSubtreeWanted()); - break; - - case COL_PRIORITY: - value.setValue (priorityString()); - break; - } - } - else if (role == Qt::DecorationRole && column == COL_NAME) - { - if (childCount () > 0) - value = qApp->style ()->standardIcon (QStyle::SP_DirOpenIcon); - else - value = Utils::guessMimeIcon (name ()); - } - - return value; -} - -void -FileTreeItem::getSubtreeWantedSize (uint64_t& have, uint64_t& total) const -{ - if (myIsWanted) - { - have += myHaveSize; - total += myTotalSize; - } - - for (const FileTreeItem * const i: myChildren) - i->getSubtreeWantedSize(have, total); -} - -double -FileTreeItem::progress () const -{ - double d(0); - uint64_t have(0), total(0); - - getSubtreeWantedSize (have, total); - if (total) - d = have / (double)total; - - return d; -} - -QString -FileTreeItem::sizeString () const -{ - QString str; - - if (myChildren.isEmpty()) - { - str = Formatter::sizeToString (myTotalSize); - } - else - { - uint64_t have = 0; - uint64_t total = 0; - getSubtreeWantedSize (have, total); - str = Formatter::sizeToString (total); - } - - return str; -} - -std::pair -FileTreeItem::update (const QString& name, - bool wanted, - int priority, - uint64_t haveSize, - bool updateFields) -{ - int changed_count = 0; - int changed_columns[4]; - - if (myName != name) - { - if (myParent) - myParent->myFirstUnhashedRow = row(); - - myName = name; - changed_columns[changed_count++] = COL_NAME; - } - - if (fileIndex () != -1) - { - if (myHaveSize != haveSize) - { - myHaveSize = haveSize; - changed_columns[changed_count++] = COL_PROGRESS; - } - - if (updateFields) - { - if (myIsWanted != wanted) - { - myIsWanted = wanted; - changed_columns[changed_count++] = COL_WANTED; - } - - if (myPriority != priority) - { - myPriority = priority; - changed_columns[changed_count++] = COL_PRIORITY; - } - } - } - - std::pair changed (-1, -1); - if (changed_count > 0) - { - std::sort (changed_columns, changed_columns+changed_count); - changed.first = changed_columns[0]; - changed.second = changed_columns[changed_count-1]; - } - return changed; -} - -QString -FileTreeItem::priorityString () const -{ - const int i = priority(); - - switch (i) - { - case LOW: return tr("Low"); - case HIGH: return tr("High"); - case NORMAL: return tr("Normal"); - default: return tr("Mixed"); - } -} - -int -FileTreeItem::priority () const -{ - int i(0); - - if (myChildren.isEmpty()) - { - switch (myPriority) - { - case TR_PRI_LOW: - i |= LOW; - break; - - case TR_PRI_HIGH: - i |= HIGH; - break; - - default: - i |= NORMAL; - break; - } - } - - for (const FileTreeItem * const child: myChildren) - i |= child->priority(); - - return i; -} - -void -FileTreeItem::setSubtreePriority (int i, QSet& ids) -{ - if (myPriority != i) - { - myPriority = i; - - if (myFileIndex >= 0) - ids.insert (myFileIndex); - } - - for (FileTreeItem * const child: myChildren) - child->setSubtreePriority (i, ids); -} - -void -FileTreeItem::twiddlePriority (QSet& ids, int& p) -{ - const int old(priority()); - - if (old & LOW) - p = TR_PRI_NORMAL; - else if (old & NORMAL) - p = TR_PRI_HIGH; - else - p = TR_PRI_LOW; - - setSubtreePriority (p, ids); -} - -int -FileTreeItem::isSubtreeWanted () const -{ - if(myChildren.isEmpty()) - return myIsWanted ? Qt::Checked : Qt::Unchecked; - - int wanted(-1); - for (const FileTreeItem * const child: myChildren) - { - const int childWanted = child->isSubtreeWanted(); - - if (wanted == -1) - wanted = childWanted; - - if (wanted != childWanted) - wanted = Qt::PartiallyChecked; - - if (wanted == Qt::PartiallyChecked) - return wanted; - } - - return wanted; -} - -void -FileTreeItem::setSubtreeWanted (bool b, QSet& ids) -{ - if (myIsWanted != b) - { - myIsWanted = b; - - if (myFileIndex >= 0) - ids.insert(myFileIndex); - } - - for (FileTreeItem * const child: myChildren) - child->setSubtreeWanted (b, ids); -} - -void -FileTreeItem::twiddleWanted (QSet& ids, bool& wanted) -{ - wanted = isSubtreeWanted() != Qt::Checked; - setSubtreeWanted (wanted, ids); -} - -QString -FileTreeItem::path () const -{ - QString itemPath; - const FileTreeItem * item = this; - - while (item != NULL && !item->name().isEmpty()) - { - if (itemPath.isEmpty()) - itemPath = item->name(); - else - itemPath = item->name() + QLatin1Char ('/') + itemPath; - item = item->parent (); - } - - return itemPath; -} - -bool -FileTreeItem::isComplete () const -{ - return myHaveSize == totalSize (); -} - -/*** -**** -**** -***/ - -FileTreeModel::FileTreeModel (QObject * parent, bool isEditable): - QAbstractItemModel(parent), - myRootItem (new FileTreeItem), - myIndexCache (), - myIsEditable (isEditable) -{ -} - -FileTreeModel::~FileTreeModel() -{ - clear(); - - delete myRootItem; -} - -void -FileTreeModel::setEditable (bool editable) -{ - myIsEditable = editable; -} - -FileTreeItem * -FileTreeModel::itemFromIndex (const QModelIndex& index) const -{ - return static_cast(index.internalPointer()); -} - -QVariant -FileTreeModel::data (const QModelIndex &index, int role) const -{ - QVariant value; - - if (index.isValid()) - value = itemFromIndex(index)->data (index.column(), role); - - return value; -} - -Qt::ItemFlags -FileTreeModel::flags (const QModelIndex& index) const -{ - int i(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - - if(myIsEditable && (index.column() == COL_NAME)) - i |= Qt::ItemIsEditable; - - if(index.column() == COL_WANTED) - i |= Qt::ItemIsUserCheckable | Qt::ItemIsTristate; - - return (Qt::ItemFlags)i; -} - -bool -FileTreeModel::setData (const QModelIndex& index, const QVariant& newname, int role) -{ - if (role == Qt::EditRole) - { - FileTreeItem * item = itemFromIndex (index); - - emit pathEdited (item->path (), newname.toString ()); - } - - return false; // don't update the view until the session confirms the change -} - -QVariant -FileTreeModel::headerData (int column, Qt::Orientation orientation, int role) const -{ - QVariant data; - - if (orientation==Qt::Horizontal && role==Qt::DisplayRole) - { - switch (column) - { - case COL_NAME: - data.setValue (tr("File")); - break; - - case COL_SIZE: - data.setValue (tr("Size")); - break; - - case COL_PROGRESS: - data.setValue (tr("Progress")); - break; - - case COL_WANTED: - data.setValue (tr("Download")); - break; - - case COL_PRIORITY: - data.setValue (tr("Priority")); - break; - - default: - break; - } - } - - return data; -} - -QModelIndex -FileTreeModel::index (int row, int column, const QModelIndex& parent) const -{ - QModelIndex i; - - if (hasIndex (row, column, parent)) - { - FileTreeItem * parentItem; - - if (!parent.isValid ()) - parentItem = myRootItem; - else - parentItem = itemFromIndex (parent); - - FileTreeItem * childItem = parentItem->child (row); - - if (childItem) - i = createIndex (row, column, childItem); - } - - return i; -} - -QModelIndex -FileTreeModel::parent (const QModelIndex& child) const -{ - return parent (child, 0); // QAbstractItemModel::parent() wants col 0 -} - -QModelIndex -FileTreeModel::parent (const QModelIndex& child, int column) const -{ - QModelIndex parent; - - if (child.isValid()) - parent = indexOf (itemFromIndex(child)->parent(), column); - - return parent; -} - -int -FileTreeModel::rowCount (const QModelIndex& parent) const -{ - FileTreeItem * parentItem; - - if (parent.isValid()) - parentItem = itemFromIndex (parent); - else - parentItem = myRootItem; - - return parentItem->childCount(); -} - -int -FileTreeModel::columnCount (const QModelIndex& parent) const -{ - Q_UNUSED(parent); - - return NUM_COLUMNS; -} - -QModelIndex -FileTreeModel::indexOf (FileTreeItem * item, int column) const -{ - if (!item || item==myRootItem) - return QModelIndex(); - - return createIndex(item->row(), column, item); -} - -void -FileTreeModel::clearSubtree (const QModelIndex& top) -{ - size_t i = rowCount (top); - - while (i > 0) - clearSubtree(index(--i, 0, top)); - - FileTreeItem * const item = itemFromIndex (top); - if (item == 0) - return; - - if (item->fileIndex () != -1) - myIndexCache.remove (item->fileIndex ()); - - delete item; -} - -void -FileTreeModel::clear () -{ - beginResetModel (); - clearSubtree (QModelIndex()); - endResetModel (); - - assert (myIndexCache.isEmpty ()); -} - -FileTreeItem * -FileTreeModel::findItemForFileIndex (int fileIndex) const -{ - return myIndexCache.value (fileIndex, 0); -} - -void -FileTreeModel::addFile (int fileIndex, - const QString & filename, - bool wanted, - int priority, - uint64_t totalSize, - uint64_t have, - QList & rowsAdded, - bool updateFields) -{ - FileTreeItem * item; - QStringList tokens = filename.split (QChar::fromLatin1('/')); - - item = findItemForFileIndex (fileIndex); - - if (item) // this file is already in the tree, we've added this - { - QModelIndex indexWithChangedParents; - while (!tokens.isEmpty()) - { - const QString token = tokens.takeLast(); - const std::pair changed = item->update (token, wanted, priority, have, updateFields); - if (changed.first >= 0) - { - dataChanged (indexOf (item, changed.first), indexOf (item, changed.second)); - if (!indexWithChangedParents.isValid () && - changed.first <= COL_PRIORITY && changed.second >= COL_SIZE) - indexWithChangedParents = indexOf (item, 0); - } - item = item->parent(); - } - assert (item == myRootItem); - if (indexWithChangedParents.isValid ()) - parentsChanged (indexWithChangedParents, COL_SIZE, COL_PRIORITY); - } - else // we haven't build the FileTreeItems for these tokens yet - { - bool added = false; - - item = myRootItem; - while (!tokens.isEmpty()) - { - const QString token = tokens.takeFirst(); - FileTreeItem * child(item->child(token)); - if (!child) - { - added = true; - QModelIndex parentIndex (indexOf(item, 0)); - const int n (item->childCount()); - - beginInsertRows (parentIndex, n, n); - if (tokens.isEmpty()) - child = new FileTreeItem (token, fileIndex, totalSize); - else - child = new FileTreeItem (token); - item->appendChild (child); - endInsertRows (); - - rowsAdded.append (indexOf(child, 0)); - } - item = child; - } - - if (item != myRootItem) - { - assert (item->fileIndex() == fileIndex); - assert (item->totalSize() == totalSize); - - myIndexCache[fileIndex] = item; - - const std::pair changed = item->update (item->name(), wanted, priority, have, added || updateFields); - if (changed.first >= 0) - dataChanged (indexOf (item, changed.first), indexOf (item, changed.second)); - } - } -} - -void -FileTreeModel::parentsChanged (const QModelIndex& index, int firstColumn, int lastColumn) -{ - assert (firstColumn <= lastColumn); - - QModelIndex walk = index; - - for (;;) - { - walk = parent (walk, firstColumn); - if (!walk.isValid ()) - break; - - dataChanged (walk, walk.sibling (walk.row (), lastColumn)); - } -} - -void -FileTreeModel::subtreeChanged (const QModelIndex& index, int firstColumn, int lastColumn) -{ - assert (firstColumn <= lastColumn); - - const int childCount = rowCount (index); - if (!childCount) - return; - - // tell everyone that this tier changed - dataChanged (index.child (0, firstColumn), index.child (childCount - 1, lastColumn)); - - // walk the subtiers - for (int i=0; i file_ids; - FileTreeItem * item; - - item = itemFromIndex (index); - item->twiddleWanted (file_ids, want); - emit wantedChanged (file_ids, want); - - dataChanged (index, index); - parentsChanged (index, COL_SIZE, COL_WANTED); - subtreeChanged (index, COL_WANTED, COL_WANTED); - } - else if (column == COL_PRIORITY) - { - int priority; - QSet file_ids; - FileTreeItem * item; - - item = itemFromIndex (index); - item->twiddlePriority (file_ids, priority); - emit priorityChanged (file_ids, priority); - - dataChanged (index, index); - parentsChanged (index, column, column); - subtreeChanged (index, column, column); - } -} - -void -FileTreeModel::doubleClicked (const QModelIndex& index) -{ - if (!index.isValid()) - return; - - const int column (index.column()); - if (column == COL_WANTED || column == COL_PRIORITY) - return; - - FileTreeItem * item = itemFromIndex (index); - - if (item->childCount () == 0 && item->isComplete ()) - emit openRequested (item->path ()); -} - -/**** -***** -****/ - -QSize -FileTreeDelegate::sizeHint(const QStyleOptionViewItem& item, const QModelIndex& index) const -{ - QSize size; - - switch(index.column()) - { - case COL_PROGRESS: - case COL_WANTED: - size = QSize(20, 1); - break; - - default: - size = QItemDelegate::sizeHint (item, index); - } - - size.rheight() += 8; // make the spacing a little nicer - return size; -} - -void -FileTreeDelegate::paint (QPainter * painter, - const QStyleOptionViewItem & option, - const QModelIndex & index) const -{ - const int column(index.column()); - - if ((column != COL_PROGRESS) && (column != COL_WANTED)) - { - QItemDelegate::paint(painter, option, index); - return; - } - - QStyle * style (qApp->style ()); - - painter->save(); - QItemDelegate::drawBackground (painter, option, index); - - if(column == COL_PROGRESS) - { - QStyleOptionProgressBar p; - p.state = option.state | QStyle::State_Small; - p.direction = qApp->layoutDirection(); - p.rect = option.rect; - p.rect.setSize (QSize(option.rect.width()-2, option.rect.height()-8)); - p.rect.moveCenter (option.rect.center()); - p.fontMetrics = qApp->fontMetrics(); - p.minimum = 0; - p.maximum = 100; - p.textAlignment = Qt::AlignCenter; - p.textVisible = true; - p.progress = (int)(100.0*index.data().toDouble()); - p.text = QString::fromLatin1 ("%1%").arg (p.progress); - style->drawControl(QStyle::CE_ProgressBar, &p, painter); - } - else if(column == COL_WANTED) - { - QStyleOptionButton o; - o.state = option.state; - o.direction = qApp->layoutDirection(); - o.rect.setSize (QSize(20, option.rect.height())); - o.rect.moveCenter (option.rect.center()); - o.fontMetrics = qApp->fontMetrics(); - switch (index.data().toInt()) - { - case Qt::Unchecked: o.state |= QStyle::State_Off; break; - case Qt::Checked: o.state |= QStyle::State_On; break; - default: o.state |= QStyle::State_NoChange;break; - } - style->drawControl (QStyle::CE_CheckBox, &o, painter); - } - - QItemDelegate::drawFocus (painter, option, option.rect); - painter->restore(); -} - -/**** -***** -***** -***** -****/ - -FileTreeView::FileTreeView (QWidget * parent, bool isEditable): - QTreeView (parent), - myModel (this, isEditable), - myProxy (new QSortFilterProxyModel()), - myDelegate (this) -{ - setSortingEnabled (true); - setAlternatingRowColors (true); - setSelectionBehavior (QAbstractItemView::SelectRows); - setSelectionMode (QAbstractItemView::ExtendedSelection); - myProxy->setSourceModel (&myModel); - setModel (myProxy); - setItemDelegate (&myDelegate); - setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); - sortByColumn (COL_NAME, Qt::AscendingOrder); - installEventFilter (this); - - for (int i=0; isetResizeMode(i, QHeaderView::Interactive); -#else - header()->setSectionResizeMode(i, QHeaderView::Interactive); -#endif - } - - connect (this, SIGNAL(clicked(QModelIndex)), - this, SLOT(onClicked(QModelIndex))); - - connect (this, SIGNAL(doubleClicked(QModelIndex)), - this, SLOT(onDoubleClicked(QModelIndex))); - - connect (&myModel, SIGNAL(priorityChanged(QSet, int)), - this, SIGNAL(priorityChanged(QSet, int))); - - connect (&myModel, SIGNAL(wantedChanged(QSet, bool)), - this, SIGNAL(wantedChanged(QSet, bool))); - - connect (&myModel, SIGNAL(pathEdited(QString, QString)), - this, SIGNAL(pathEdited(QString, QString))); - - connect (&myModel, SIGNAL (openRequested (QString)), - this, SLOT (onOpenRequested (QString)), - Qt::QueuedConnection); -} - -FileTreeView::~FileTreeView () -{ - myProxy->deleteLater(); -} - -void -FileTreeView::onClicked (const QModelIndex& proxyIndex) -{ - const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex); - myModel.clicked (modelIndex); -} - -void -FileTreeView::onDoubleClicked (const QModelIndex& proxyIndex) -{ - const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex); - myModel.doubleClicked (modelIndex); -} - -void -FileTreeView::onOpenRequested (const QString& path) -{ - if (state () == EditingState) - return; - - emit openRequested (path); -} - -bool -FileTreeView::eventFilter (QObject * o, QEvent * event) -{ - // this is kind of a hack to get the last three columns be the - // right size, and to have the filename column use whatever - // space is left over... - if ((o == this) && (event->type() == QEvent::Resize)) - { - QResizeEvent * r = static_cast (event); - int left = r->size().width(); - const QFontMetrics fontMetrics(font()); - for (int column=FIRST_VISIBLE_COLUMN; column<=LAST_VISIBLE_COLUMN; ++column) - { - if (column == COL_NAME) - continue; - if (isColumnHidden (column)) - continue; - - QString header; - if (column == COL_SIZE) - header = QLatin1String ("999.9 KiB"); - else - header = myModel.headerData (column, Qt::Horizontal).toString(); - header += QLatin1String (" "); - const int width = fontMetrics.size (0, header).width(); - setColumnWidth (column, width); - left -= width; - } - left -= 20; // not sure why this is necessary. it works in different themes + font sizes though... - setColumnWidth(COL_NAME, std::max(left,0)); - } - - // handle using the keyboard to toggle the - // wanted/unwanted state or the file priority - else if (event->type () == QEvent::KeyPress && state () != EditingState) - { - switch (static_cast (event)->key ()) - { - case Qt::Key_Space: - for (const QModelIndex& i: selectionModel ()->selectedRows (COL_WANTED)) - clicked (i); - break; - - case Qt::Key_Enter: - case Qt::Key_Return: - for (const QModelIndex& i: selectionModel ()->selectedRows (COL_PRIORITY)) - clicked (i); - break; - } - } - - return false; -} - -void -FileTreeView::update (const FileList& files, bool updateFields) -{ - for (const TrFile& file: files) - { - QList added; - myModel.addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, updateFields); - for (const QModelIndex& i: added) - expand (myProxy->mapFromSource(i)); - } -} - -void -FileTreeView::clear () -{ - myModel.clear(); -} - -void -FileTreeView::setEditable (bool editable) -{ - myModel.setEditable (editable); -} diff --git a/qt/file-tree.h b/qt/file-tree.h deleted file mode 100644 index 5460b82a7..000000000 --- a/qt/file-tree.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * This file Copyright (C) 2009-2014 Mnemosyne LLC - * - * It may be used under the GNU GPL versions 2 or 3 - * or any future license endorsed by Mnemosyne LLC. - * - * $Id$ - */ - -#ifndef QTR_FILE_TREE -#define QTR_FILE_TREE - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class QSortFilterProxyModel; -class QStyle; - -#include "torrent.h" // FileList - -/**** -***** -****/ - -class FileTreeItem: public QObject -{ - Q_OBJECT - - enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) }; - - public: - - virtual ~FileTreeItem(); - - FileTreeItem (const QString& name=QString (), int fileIndex=-1, uint64_t size=0): - myFileIndex (fileIndex), - myParent (0), - myName (name), - myPriority (0), - myIsWanted (0), - myHaveSize (0), - myTotalSize (size), - myFirstUnhashedRow (0) {} - - public: - void appendChild (FileTreeItem *child); - FileTreeItem * child (const QString& filename); - FileTreeItem * child (int row) { return myChildren.at(row); } - int childCount () const { return myChildren.size(); } - FileTreeItem * parent () { return myParent; } - const FileTreeItem * parent () const { return myParent; } - int row () const; - const QString& name () const { return myName; } - QVariant data (int column, int role) const; - std::pair update (const QString& name, bool want, int priority, uint64_t have, bool updateFields); - void twiddleWanted (QSet& fileIds, bool&); - void twiddlePriority (QSet& fileIds, int&); - int fileIndex () const { return myFileIndex; } - uint64_t totalSize () const { return myTotalSize; } - QString path () const; - bool isComplete () const; - - private: - void setSubtreePriority (int priority, QSet& fileIds); - void setSubtreeWanted (bool, QSet& fileIds); - QString priorityString () const; - QString sizeString () const; - void getSubtreeWantedSize (uint64_t& have, uint64_t& total) const; - double progress () const; - int priority () const; - int isSubtreeWanted () const; - - const int myFileIndex; - FileTreeItem * myParent; - QList myChildren; - QHash myChildRows; - const QHash& getMyChildRows(); - QString myName; - int myPriority; - bool myIsWanted; - uint64_t myHaveSize; - const uint64_t myTotalSize; - size_t myFirstUnhashedRow; -}; - -class FileTreeModel: public QAbstractItemModel -{ - Q_OBJECT - - public: - FileTreeModel (QObject *parent = 0, bool isEditable = true); - ~FileTreeModel (); - - void setEditable (bool editable); - - public: - QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const; - Qt::ItemFlags flags (const QModelIndex& index) const; - QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const; - QModelIndex parent (const QModelIndex& child) const; - QModelIndex parent (const QModelIndex& child, int column) const; - int rowCount (const QModelIndex& parent = QModelIndex()) const; - int columnCount (const QModelIndex &parent = QModelIndex()) const; - virtual bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); - - signals: - void priorityChanged (const QSet& fileIndices, int); - void wantedChanged (const QSet& fileIndices, bool); - void pathEdited (const QString& oldpath, const QString& newname); - void openRequested (const QString& path); - - public: - void clear (); - void addFile (int index, const QString& filename, - bool wanted, int priority, - uint64_t size, uint64_t have, - QList& rowsAdded, - bool torrentChanged); - - private: - void clearSubtree (const QModelIndex &); - QModelIndex indexOf (FileTreeItem *, int column) const; - void parentsChanged (const QModelIndex &, int firstColumn, int lastColumn); - void subtreeChanged (const QModelIndex &, int firstColumn, int lastColumn); - FileTreeItem * findItemForFileIndex (int fileIndex) const; - FileTreeItem * itemFromIndex (const QModelIndex&) const; - - private: - FileTreeItem * myRootItem; - QMap myIndexCache; - bool myIsEditable; - - public slots: - void clicked (const QModelIndex & index); - void doubleClicked (const QModelIndex & index); -}; - -class FileTreeDelegate: public QItemDelegate -{ - Q_OBJECT - - public: - FileTreeDelegate (QObject * parent=0): QItemDelegate(parent) {} - virtual ~FileTreeDelegate() {} - - public: - virtual QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const; - virtual void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const; -}; - -class FileTreeView: public QTreeView -{ - Q_OBJECT - - public: - FileTreeView (QWidget * parent=0, bool editable=true); - virtual ~FileTreeView (); - void clear (); - void update (const FileList& files, bool updateProperties=true); - - void setEditable (bool editable); - - signals: - void priorityChanged (const QSet& fileIndices, int priority); - void wantedChanged (const QSet& fileIndices, bool wanted); - void pathEdited (const QString& oldpath, const QString& newname); - void openRequested (const QString& path); - - protected: - bool eventFilter (QObject *, QEvent *); - - private: - FileTreeModel myModel; - QSortFilterProxyModel * myProxy; - FileTreeDelegate myDelegate; - - public slots: - void onClicked (const QModelIndex& index); - void onDoubleClicked (const QModelIndex& index); - void onOpenRequested (const QString& path); -}; - -#endif diff --git a/qt/filterbar.cc b/qt/filterbar.cc deleted file mode 100644 index b73b25828..000000000 --- a/qt/filterbar.cc +++ /dev/null @@ -1,728 +0,0 @@ -/* - * This file Copyright (C) 2012-2014 Mnemosyne LLC - * - * It may be used under the GNU GPL versions 2 or 3 - * or any future license endorsed by Mnemosyne LLC. - * - * $Id$ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "app.h" -#include "favicon.h" -#include "filters.h" -#include "filterbar.h" -#include "hig.h" -#include "prefs.h" -#include "torrent-filter.h" -#include "torrent-model.h" -#include "utils.h" - -/**** -***** -***** DELEGATE -***** -****/ - -enum -{ - TorrentCountRole = Qt::UserRole + 1, - TorrentCountStringRole, - ActivityRole, - TrackerRole -}; - -namespace -{ - int getHSpacing (const QWidget * w) - { - return qMax (int (HIG::PAD_SMALL), w->style ()->pixelMetric (QStyle::PM_LayoutHorizontalSpacing, 0, w)); - } - - QColor - getFadedColor (const QColor& color) - { - QColor fadedColor (color); - fadedColor.setAlpha (128); - return fadedColor; - } -} - -FilterBarComboBoxDelegate::FilterBarComboBoxDelegate (QObject * parent, QComboBox * combo): - QItemDelegate (parent), - myCombo (combo) -{ -} - -bool -FilterBarComboBoxDelegate::isSeparator (const QModelIndex& index) -{ - return index.data (Qt::AccessibleDescriptionRole).toString () == QLatin1String ("separator"); -} -void -FilterBarComboBoxDelegate::setSeparator (QAbstractItemModel * model, const QModelIndex& index) -{ - model->setData (index, QString::fromLatin1 ("separator"), Qt::AccessibleDescriptionRole); - - if (QStandardItemModel *m = qobject_cast (model)) - if (QStandardItem *item = m->itemFromIndex (index)) - item->setFlags (item->flags () & ~ (Qt::ItemIsSelectable|Qt::ItemIsEnabled)); -} - -void -FilterBarComboBoxDelegate::paint (QPainter * painter, - const QStyleOptionViewItem & option, - const QModelIndex & index) const -{ - if (isSeparator (index)) - { - QRect rect = option.rect; - if (const QStyleOptionViewItemV3 *v3 = qstyleoption_cast (&option)) - if (const QAbstractItemView *view = qobject_cast (v3->widget)) - rect.setWidth (view->viewport ()->width ()); - QStyleOption opt; - opt.rect = rect; - myCombo->style ()->drawPrimitive (QStyle::PE_IndicatorToolBarSeparator, &opt, painter, myCombo); - } - else - { - QStyleOptionViewItem disabledOption = option; - const QPalette::ColorRole disabledColorRole = (disabledOption.state & QStyle::State_Selected) ? - QPalette::HighlightedText : QPalette::Text; - disabledOption.palette.setColor (disabledColorRole, getFadedColor (disabledOption.palette.color (disabledColorRole))); - - QRect boundingBox = option.rect; - - const int hmargin = getHSpacing (myCombo); - boundingBox.adjust (hmargin, 0, -hmargin, 0); - - QRect decorationRect = rect (option, index, Qt::DecorationRole); - decorationRect.setSize (myCombo->iconSize ()); - decorationRect = QStyle::alignedRect (option.direction, - Qt::AlignLeft|Qt::AlignVCenter, - decorationRect.size (), boundingBox); - Utils::narrowRect (boundingBox, decorationRect.width () + hmargin, 0, option.direction); - - QRect countRect = rect (option, index, TorrentCountStringRole); - countRect = QStyle::alignedRect (option.direction, - Qt::AlignRight|Qt::AlignVCenter, - countRect.size (), boundingBox); - Utils::narrowRect (boundingBox, 0, countRect.width () + hmargin, option.direction); - const QRect displayRect = boundingBox; - - drawBackground (painter, option, index); - QStyleOptionViewItem option2 = option; - option2.decorationSize = myCombo->iconSize (); - drawDecoration (painter, option, decorationRect, decoration (option2,index.data (Qt::DecorationRole))); - drawDisplay (painter, option, displayRect, index.data (Qt::DisplayRole).toString ()); - drawDisplay (painter, disabledOption, countRect, index.data (TorrentCountStringRole).toString ()); - drawFocus (painter, option, displayRect|countRect); - } -} - -QSize -FilterBarComboBoxDelegate::sizeHint (const QStyleOptionViewItem & option, - const QModelIndex & index) const -{ - if (isSeparator (index)) - { - const int pm = myCombo->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth, 0, myCombo); - return QSize (pm, pm + 10); - } - else - { - QStyle * s = myCombo->style (); - const int hmargin = getHSpacing (myCombo); - - QSize size = QItemDelegate::sizeHint (option, index); - size.setHeight (qMax (size.height (), myCombo->iconSize ().height () + 6)); - size.rwidth () += s->pixelMetric (QStyle::PM_FocusFrameHMargin, 0, myCombo); - size.rwidth () += rect (option,index,TorrentCountStringRole).width (); - size.rwidth () += hmargin * 4; - return size; - } -} - -/** -*** -**/ - -FilterBarComboBox::FilterBarComboBox (QWidget * parent): - QComboBox (parent) -{ - setSizeAdjustPolicy (QComboBox::AdjustToContents); -} - -int -FilterBarComboBox::currentCount () const -{ - int count = 0; - - const QModelIndex modelIndex = model ()->index (currentIndex (), 0, rootModelIndex ()); - if (modelIndex.isValid ()) - count = modelIndex.data (TorrentCountRole).toInt (); - - return count; -} - -QSize -FilterBarComboBox::minimumSizeHint () const -{ - QFontMetrics fm (fontMetrics ()); - const QSize textSize = fm.boundingRect (itemText (0)).size (); - const QSize countSize = fm.boundingRect (itemData (0, TorrentCountStringRole).toString ()).size (); - return calculateSize (textSize, countSize); -} - -QSize -FilterBarComboBox::sizeHint () const -{ - QFontMetrics fm (fontMetrics ()); - QSize maxTextSize (0, 0); - QSize maxCountSize (0, 0); - for (int i = 0, n = count (); i < n; ++i) - { - const QSize textSize = fm.boundingRect (itemText (i)).size (); - maxTextSize.setHeight (qMax (maxTextSize.height (), textSize.height ())); - maxTextSize.setWidth (qMax (maxTextSize.width (), textSize.width ())); - - const QSize countSize = fm.boundingRect (itemData (i, TorrentCountStringRole).toString ()).size (); - maxCountSize.setHeight (qMax (maxCountSize.height (), countSize.height ())); - maxCountSize.setWidth (qMax (maxCountSize.width (), countSize.width ())); - } - - return calculateSize (maxTextSize, maxCountSize); -} - -QSize -FilterBarComboBox::calculateSize (const QSize& textSize, const QSize& countSize) const -{ - const int hmargin = getHSpacing (this); - - QStyleOptionComboBox option; - initStyleOption (&option); - - QSize contentSize = iconSize () + QSize (4, 2); - contentSize.setHeight (qMax (contentSize.height (), textSize.height ())); - contentSize.rwidth () += hmargin + textSize.width (); - contentSize.rwidth () += hmargin + countSize.width (); - - return style ()->sizeFromContents (QStyle::CT_ComboBox, &option, contentSize, this).expandedTo (qApp->globalStrut ()); -} - -void -FilterBarComboBox::paintEvent (QPaintEvent * e) -{ - Q_UNUSED (e); - - QStylePainter painter (this); - painter.setPen (palette ().color (QPalette::Text)); - - // draw the combobox frame, focusrect and selected etc. - QStyleOptionComboBox opt; - initStyleOption (&opt); - painter.drawComplexControl (QStyle::CC_ComboBox, opt); - - // draw the icon and text - const QModelIndex modelIndex = model ()->index (currentIndex (), 0, rootModelIndex ()); - if (modelIndex.isValid ()) - { - QStyle * s = style (); - const int hmargin = getHSpacing (this); - - QRect rect = s->subControlRect (QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this); - rect.adjust (2, 1, -2, -1); - - // draw the icon - QPixmap pixmap; - QVariant variant = modelIndex.data (Qt::DecorationRole); - switch (variant.type ()) - { - case QVariant::Pixmap: pixmap = qvariant_cast (variant); break; - case QVariant::Icon: pixmap = qvariant_cast (variant).pixmap (iconSize ()); break; - default: break; - } - if (!pixmap.isNull ()) - { - const QRect iconRect = QStyle::alignedRect(opt.direction, Qt::AlignLeft | Qt::AlignVCenter, - opt.iconSize, rect); - painter.drawPixmap (iconRect.topLeft (), pixmap); - Utils::narrowRect (rect, iconRect.width () + hmargin, 0, opt.direction); - } - - // draw the count - QString text = modelIndex.data (TorrentCountStringRole).toString (); - if (!text.isEmpty ()) - { - const QPen pen = painter.pen (); - painter.setPen (getFadedColor (pen.color ())); - const QRect textRect = QStyle::alignedRect(opt.direction, Qt::AlignRight | Qt::AlignVCenter, - QSize (opt.fontMetrics.width (text), rect.height ()), rect); - painter.drawText (textRect, Qt::AlignRight | Qt::AlignVCenter, text); - Utils::narrowRect (rect, 0, textRect.width () + hmargin, opt.direction); - painter.setPen (pen); - } - - // draw the text - text = modelIndex.data (Qt::DisplayRole).toString (); - text = painter.fontMetrics ().elidedText (text, Qt::ElideRight, rect.width ()); - painter.drawText (rect, Qt::AlignLeft | Qt::AlignVCenter, text); - } -} - -/**** -***** -****/ - -FilterBarLineEdit::FilterBarLineEdit (QWidget * parent): - QLineEdit (parent), - myClearButton (nullptr) -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const QIcon icon = QIcon::fromTheme (QLatin1String ("edit-clear"), style ()->standardIcon (QStyle::SP_DialogCloseButton)); - const int iconSize = style ()->pixelMetric (QStyle::PM_SmallIconSize); - - myClearButton = new QToolButton (this); - myClearButton->setStyleSheet (QLatin1String ("QToolButton{border:0;padding:0;margin:0}")); - myClearButton->setToolButtonStyle (Qt::ToolButtonIconOnly); - myClearButton->setFocusPolicy (Qt::NoFocus); - myClearButton->setCursor (Qt::ArrowCursor); - myClearButton->setIconSize (QSize (iconSize, iconSize)); - myClearButton->setIcon (icon); - myClearButton->setFixedSize (myClearButton->iconSize () + QSize (2, 2)); - myClearButton->hide (); - - const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); - const QSize minSizeHint = minimumSizeHint (); - const QSize buttonSize = myClearButton->size (); - - setStyleSheet (QString::fromLatin1 ("QLineEdit{padding-right:%1px}").arg (buttonSize.width () + frameWidth + 1)); - setMinimumSize (qMax (minSizeHint.width (), buttonSize.width () + frameWidth * 2 + 2), - qMax (minSizeHint.height (), buttonSize.height () + frameWidth * 2 + 2)); - - connect (this, SIGNAL (textChanged (QString)), this, SLOT (updateClearButtonVisibility ())); - connect (myClearButton, SIGNAL (clicked ()), this, SLOT (clear ())); -#else - setClearButtonEnabled (true); -#endif - -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - setPlaceholderText (tr ("Search...")); -#endif -} - -void -FilterBarLineEdit::resizeEvent (QResizeEvent * event) -{ - QLineEdit::resizeEvent (event); - -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); - const QRect editRect = rect(); - const QSize buttonSize = myClearButton->size (); - - myClearButton->move (editRect.right () - frameWidth - buttonSize.width (), - editRect.top () + (editRect.height () - buttonSize.height ()) / 2); -#endif -} - -void -FilterBarLineEdit::updateClearButtonVisibility () -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - myClearButton->setVisible (!text ().isEmpty ()); -#endif -} - -/**** -***** -***** ACTIVITY -***** -****/ - -FilterBarComboBox * -FilterBar::createActivityCombo () -{ - FilterBarComboBox * c = new FilterBarComboBox (this); - FilterBarComboBoxDelegate * delegate = new FilterBarComboBoxDelegate (this, c); - c->setItemDelegate (delegate); - - QStandardItemModel * model = new QStandardItemModel (this); - - QStandardItem * row = new QStandardItem (tr ("All")); - row->setData (FilterMode::SHOW_ALL, ActivityRole); - model->appendRow (row); - - model->appendRow (new QStandardItem); // separator - delegate->setSeparator (model, model->index (1, 0)); - - row = new QStandardItem (QIcon::fromTheme (QLatin1String ("system-run")), tr ("Active")); - row->setData (FilterMode::SHOW_ACTIVE, ActivityRole); - model->appendRow (row); - - row = new QStandardItem (QIcon::fromTheme (QLatin1String ("go-down")), tr ("Downloading")); - row->setData (FilterMode::SHOW_DOWNLOADING, ActivityRole); - model->appendRow (row); - - row = new QStandardItem (QIcon::fromTheme (QLatin1String ("go-up")), tr ("Seeding")); - row->setData (FilterMode::SHOW_SEEDING, ActivityRole); - model->appendRow (row); - - row = new QStandardItem (QIcon::fromTheme (QLatin1String ("media-playback-pause")), tr ("Paused")); - row->setData (FilterMode::SHOW_PAUSED, ActivityRole); - model->appendRow (row); - - row = new QStandardItem (QIcon::fromTheme (QLatin1String ("dialog-ok")), tr ("Finished")); - row->setData (FilterMode::SHOW_FINISHED, ActivityRole); - model->appendRow (row); - - row = new QStandardItem (QIcon::fromTheme (QLatin1String ("view-refresh")), tr ("Verifying")); - row->setData (FilterMode::SHOW_VERIFYING, ActivityRole); - model->appendRow (row); - - row = new QStandardItem (QIcon::fromTheme (QLatin1String ("process-stop")), tr ("Error")); - row->setData (FilterMode::SHOW_ERROR, ActivityRole); - model->appendRow (row); - - c->setModel (model); - return c; -} - -/**** -***** -***** -***** -****/ - -namespace -{ - QString readableHostName (const QString& host) - { - // get the readable name... - QString name = host; - const int pos = name.lastIndexOf (QLatin1Char ('.')); - if (pos >= 0) - name.truncate (pos); - if (!name.isEmpty ()) - name[0] = name[0].toUpper (); - return name; - } -} - -void -FilterBar::refreshTrackers () -{ - Favicons& favicons = qApp->favicons; - const int firstTrackerRow = 2; // skip over the "All" and separator... - - // pull info from the tracker model... - QSet oldHosts; - for (int row=firstTrackerRow; ; ++row) - { - QModelIndex index = myTrackerModel->index (row, 0); - if (!index.isValid ()) - break; - oldHosts << index.data (TrackerRole).toString (); - } - - // pull the new stats from the torrent model... - QSet newHosts; - QMap torrentsPerHost; - for (int row=0; ; ++row) - { - QModelIndex index = myTorrents.index (row, 0); - if (!index.isValid ()) - break; - const Torrent * tor = index.data (TorrentModel::TorrentRole).value (); - QSet torrentNames; - for (const QString& host: tor->hosts ()) - { - newHosts.insert (host); - torrentNames.insert (readableHostName (host)); - } - for (const QString& name: torrentNames) - ++torrentsPerHost[name]; - } - - // update the "All" row - myTrackerModel->setData (myTrackerModel->index (0,0), myTorrents.rowCount (), TorrentCountRole); - myTrackerModel->setData (myTrackerModel->index (0,0), getCountString (myTorrents.rowCount ()), TorrentCountStringRole); - - // rows to update - for (const QString& host: oldHosts & newHosts) - { - const QString name = readableHostName (host); - QStandardItem * row = myTrackerModel->findItems (name).front (); - const int count = torrentsPerHost[name]; - row->setData (count, TorrentCountRole); - row->setData (getCountString (count), TorrentCountStringRole); - row->setData (favicons.findFromHost (host), Qt::DecorationRole); - } - - // rows to remove - for (const QString& host: oldHosts - newHosts) - { - const QString name = readableHostName (host); - QStandardItem * item = myTrackerModel->findItems (name).front (); - if (!item->data (TrackerRole).toString ().isEmpty ()) // don't remove "All" - myTrackerModel->removeRows (item->row (), 1); - } - - // rows to add - bool anyAdded = false; - for (const QString& host: newHosts - oldHosts) - { - const QString name = readableHostName (host); - - if (!myTrackerModel->findItems (name).isEmpty ()) - continue; - - // find the sorted position to add this row - int i = firstTrackerRow; - for (int n=myTrackerModel->rowCount (); iindex (i,0).data (Qt::DisplayRole).toString (); - if (rowName >= name) - break; - } - - // add the row - QStandardItem * row = new QStandardItem (favicons.findFromHost (host), name); - const int count = torrentsPerHost[host]; - row->setData (count, TorrentCountRole); - row->setData (getCountString (count), TorrentCountStringRole); - row->setData (favicons.findFromHost (host), Qt::DecorationRole); - row->setData (host, TrackerRole); - myTrackerModel->insertRow (i, row); - anyAdded = true; - } - - if (anyAdded) // the one added might match our filter... - refreshPref (Prefs::FILTER_TRACKERS); -} - - -FilterBarComboBox * -FilterBar::createTrackerCombo (QStandardItemModel * model) -{ - FilterBarComboBox * c = new FilterBarComboBox (this); - FilterBarComboBoxDelegate * delegate = new FilterBarComboBoxDelegate (this, c); - c->setItemDelegate (delegate); - - QStandardItem * row = new QStandardItem (tr ("All")); - row->setData (QString (), TrackerRole); - const int count = myTorrents.rowCount (); - row->setData (count, TorrentCountRole); - row->setData (getCountString (count), TorrentCountStringRole); - model->appendRow (row); - - model->appendRow (new QStandardItem); // separator - delegate->setSeparator (model, model->index (1, 0)); - - c->setModel (model); - return c; -} - -/**** -***** -***** -***** -****/ - -FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentFilter& filter, QWidget * parent): - QWidget (parent), - myPrefs (prefs), - myTorrents (torrents), - myFilter (filter), - myRecountTimer (new QTimer (this)), - myIsBootstrapping (true) -{ - QHBoxLayout * h = new QHBoxLayout (this); - h->setContentsMargins (3, 3, 3, 3); - - myCountLabel = new QLabel (this); - h->addWidget (myCountLabel); - - myActivityCombo = createActivityCombo (); - myActivityCombo->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); - h->addWidget (myActivityCombo); - - myTrackerModel = new QStandardItemModel (this); - myTrackerCombo = createTrackerCombo (myTrackerModel); - h->addWidget (myTrackerCombo); - - myLineEdit = new FilterBarLineEdit (this); - h->addWidget (myLineEdit); - connect (myLineEdit, SIGNAL (textChanged (QString)), this, SLOT (onTextChanged (QString))); - - // listen for changes from the other players - connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (int))); - connect (myActivityCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onActivityIndexChanged (int))); - connect (myTrackerCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (onTrackerIndexChanged (int))); - connect (&myFilter, SIGNAL (rowsInserted (QModelIndex, int, int)), this, SLOT (refreshCountLabel ())); - connect (&myFilter, SIGNAL (rowsRemoved (QModelIndex, int, int)), this, SLOT (refreshCountLabel ())); - connect (&myTorrents, SIGNAL (modelReset ()), this, SLOT (onTorrentModelReset ())); - connect (&myTorrents, SIGNAL (rowsInserted (QModelIndex, int, int)), this, SLOT (onTorrentModelRowsInserted (QModelIndex, int, int))); - connect (&myTorrents, SIGNAL (rowsRemoved (QModelIndex, int, int)), this, SLOT (onTorrentModelRowsRemoved (QModelIndex, int, int))); - connect (&myTorrents, SIGNAL (dataChanged (QModelIndex, QModelIndex)), this, SLOT (onTorrentModelDataChanged (QModelIndex, QModelIndex))); - connect (myRecountTimer, SIGNAL (timeout ()), this, SLOT (recount ())); - - recountSoon (); - refreshTrackers (); - refreshCountLabel (); - myIsBootstrapping = false; - - // initialize our state - QList initKeys; - initKeys << Prefs::FILTER_MODE - << Prefs::FILTER_TRACKERS; - for (const int key: initKeys) - refreshPref (key); -} - -FilterBar::~FilterBar () -{ - delete myRecountTimer; -} - -/*** -**** -***/ - -void -FilterBar::refreshPref (int key) -{ - switch (key) - { - case Prefs::FILTER_MODE: - { - const FilterMode m = myPrefs.get (key); - QAbstractItemModel * model = myActivityCombo->model (); - QModelIndexList indices = model->match (model->index (0,0), ActivityRole, m.mode ()); - myActivityCombo->setCurrentIndex (indices.isEmpty () ? 0 : indices.first ().row ()); - break; - } - - case Prefs::FILTER_TRACKERS: - { - const QString tracker = myPrefs.getString (key); - const QString name = readableHostName (tracker); - QList rows = myTrackerModel->findItems (name); - if (!rows.isEmpty ()) - { - myTrackerCombo->setCurrentIndex (rows.front ()->row ()); - } - else // hm, we don't seem to have this tracker anymore... - { - const bool isBootstrapping = myTrackerModel->rowCount () <= 2; - if (!isBootstrapping) - myPrefs.set (key, QString ()); - } - break; - } - } -} - -void -FilterBar::onTextChanged (const QString& str) -{ - if (!myIsBootstrapping) - myPrefs.set (Prefs::FILTER_TEXT, str.trimmed ()); -} - -void -FilterBar::onTrackerIndexChanged (int i) -{ - if (!myIsBootstrapping) - { - QString str; - const bool isTracker = !myTrackerCombo->itemData (i,TrackerRole).toString ().isEmpty (); - if (!isTracker) - { - // show all - } - else - { - str = myTrackerCombo->itemData (i,TrackerRole).toString (); - const int pos = str.lastIndexOf (QLatin1Char ('.')); - if (pos >= 0) - str.truncate (pos+1); - } - myPrefs.set (Prefs::FILTER_TRACKERS, str); - } -} - -void -FilterBar::onActivityIndexChanged (int i) -{ - if (!myIsBootstrapping) - { - const FilterMode mode = myActivityCombo->itemData (i, ActivityRole).toInt (); - myPrefs.set (Prefs::FILTER_MODE, mode); - } -} - -/*** -**** -***/ - -void FilterBar::onTorrentModelReset () { recountSoon (); } -void FilterBar::onTorrentModelRowsInserted (const QModelIndex&, int, int) { recountSoon (); } -void FilterBar::onTorrentModelRowsRemoved (const QModelIndex&, int, int) { recountSoon (); } -void FilterBar::onTorrentModelDataChanged (const QModelIndex&, const QModelIndex&) { recountSoon (); } - -void -FilterBar::recountSoon () -{ - if (!myRecountTimer->isActive ()) - { - myRecountTimer->setSingleShot (true); - myRecountTimer->start (800); - } -} -void -FilterBar::recount () -{ - QAbstractItemModel * model = myActivityCombo->model (); - - int torrentsPerMode[FilterMode::NUM_MODES] = {}; - myFilter.countTorrentsPerMode (torrentsPerMode); - - for (int row=0, n=model->rowCount (); rowindex (row, 0); - const int mode = index.data (ActivityRole).toInt (); - const int count = torrentsPerMode [mode]; - model->setData (index, count, TorrentCountRole); - model->setData (index, getCountString (count), TorrentCountStringRole); - } - - refreshTrackers (); - refreshCountLabel (); -} - -QString -FilterBar::getCountString (int n) const -{ - return QString::fromLatin1 ("%L1").arg (n); -} - -void -FilterBar::refreshCountLabel () -{ - const int visibleCount = myFilter.rowCount (); - const int trackerCount = myTrackerCombo->currentCount (); - const int activityCount = myActivityCombo->currentCount (); - - if ((visibleCount == activityCount) || (visibleCount == trackerCount)) - myCountLabel->setText (tr("Show:")); - else - myCountLabel->setText (tr("Show %Ln of:", 0, visibleCount)); -} diff --git a/qt/hig.cc b/qt/hig.cc deleted file mode 100644 index 873c38634..000000000 --- a/qt/hig.cc +++ /dev/null @@ -1,240 +0,0 @@ -/* - * This file Copyright (C) 2009-2014 Mnemosyne LLC - * - * It may be used under the GNU GPL versions 2 or 3 - * or any future license endorsed by Mnemosyne LLC. - * - * $Id$ - */ - -#include - -#include -#include -#include -#include - -#include "hig.h" - - -HIG::HIG (QWidget * parent): - QWidget (parent), - myRow (0), - myHasTall (false), - myGrid (new QGridLayout (this)) -{ - myGrid->setContentsMargins (PAD_BIG, PAD_BIG, PAD_BIG, PAD_BIG); - myGrid->setHorizontalSpacing (PAD_BIG); - myGrid->setVerticalSpacing (PAD); - myGrid->setColumnStretch (1, 1); -} - -HIG::~HIG () -{ - delete myGrid; -} - -/*** -**** -***/ - -void -HIG::addSectionDivider () -{ - QWidget * w = new QWidget (this); - myGrid->addWidget (w, myRow, 0, 1, 2); - ++myRow; -} - -void -HIG::addSectionTitle (const QString& title) -{ - QLabel * label = new QLabel (this); - label->setText (title); - label->setStyleSheet (QLatin1String ("font: bold")); - label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter); - addSectionTitle (label); -} - -void -HIG::addSectionTitle (QWidget * w) -{ - myGrid->addWidget (w, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter); - ++myRow; -} - -void -HIG::addSectionTitle (QLayout * l) -{ - myGrid->addLayout (l, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter); - ++myRow; -} - - -QLayout * -HIG::addRow (QWidget * w) -{ - QHBoxLayout * h = new QHBoxLayout (); - h->addSpacing (18); - h->addWidget (w); - - QLabel * l; - if ((l = qobject_cast(w))) - l->setAlignment (Qt::AlignLeft); - - return h; -} - -void -HIG::addWideControl (QLayout * l) -{ - QHBoxLayout * h = new QHBoxLayout (); - h->addSpacing (18); - h->addLayout (l); - myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter); - ++myRow; -} - -void -HIG::addWideControl (QWidget * w) -{ - QHBoxLayout * h = new QHBoxLayout (); - h->addSpacing (18); - h->addWidget (w); - myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter); - ++myRow; -} - -QCheckBox* -HIG::addWideCheckBox (const QString& text, bool isChecked) -{ - QCheckBox * check = new QCheckBox (text, this); - check->setChecked (isChecked); - addWideControl (check); - return check; -} - -void -HIG::addLabel (QWidget * w) -{ - QHBoxLayout * h = new QHBoxLayout (); - h->addSpacing (18); - h->addWidget (w); - myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignVCenter); -} - -QLabel* -HIG::addLabel (const QString& text) -{ - QLabel * label = new QLabel (text, this); - addLabel (label); - return label; -} - -void -HIG::addTallLabel (QWidget * w) -{ - QHBoxLayout * h = new QHBoxLayout (); - h->addSpacing (18); - h->addWidget (w); - myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignTop); -} - -QLabel* -HIG::addTallLabel (const QString& text) -{ - QLabel * label = new QLabel (text, this); - addTallLabel (label); - return label; -} - -void -HIG::addControl (QWidget * w) -{ - myGrid->addWidget (w, myRow, 1, 1, 1); -} - -void -HIG::addControl (QLayout * l) -{ - myGrid->addLayout (l, myRow, 1, 1, 1); -} - -QLabel * -HIG::addRow (const QString& text, QWidget * control, QWidget * buddy) -{ - QLabel * label = addLabel (text); - addControl (control); - label->setBuddy (buddy ? buddy : control); - ++myRow; - return label; -} - -QLabel * -HIG::addTallRow (const QString& text, QWidget * control, QWidget * buddy) -{ - QLabel* label = addTallLabel (text); - label->setBuddy (buddy ? buddy : control); - addControl (control); - myHasTall = true; - myGrid->setRowStretch (myRow, 1); - ++myRow; - return label; -} - -QLabel * -HIG::addRow (const QString& text, QLayout * control, QWidget * buddy) -{ - QLabel * label = addLabel (text); - addControl (control); - if (buddy != 0) - label->setBuddy (buddy); - ++myRow; - return label; -} - -void -HIG::addRow (QWidget * label, QWidget * control, QWidget * buddy) -{ - addLabel (label); - - if (control) - { - addControl (control); - - QLabel * l = qobject_cast (label); - if (l != 0) - l->setBuddy (buddy ? buddy : control); - } - - ++myRow; -} - -void -HIG::addRow (QWidget * label, QLayout * control, QWidget * buddy) -{ - addLabel (label); - - if (control) - { - addControl (control); - - QLabel * l = qobject_cast (label); - if (l != 0 && buddy != 0) - l->setBuddy (buddy); - } - - ++myRow; -} - -void -HIG::finish () -{ - if (!myHasTall) - { - QWidget * w = new QWidget (this); - myGrid->addWidget (w, myRow, 0, 1, 2); - myGrid->setRowStretch (myRow, 100); - ++myRow; - } -} diff --git a/qt/hig.h b/qt/hig.h deleted file mode 100644 index d597a6088..000000000 --- a/qt/hig.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file Copyright (C) 2009-2014 Mnemosyne LLC - * - * It may be used under the GNU GPL versions 2 or 3 - * or any future license endorsed by Mnemosyne LLC. - * - * $Id$ - */ - - -#ifndef QTR_HIG_H -#define QTR_HIG_H - -#include - -class QCheckBox; -class QLabel; -class QString; -class QGridLayout; -class QLayout; - -class HIG: public QWidget -{ - Q_OBJECT - - public: - - enum - { - PAD_SMALL = 3, - PAD = 6, - PAD_BIG = 12, - PAD_LARGE = PAD_BIG - }; - - public: - - HIG (QWidget * parent = 0); - virtual ~HIG (); - - public: - - void addSectionDivider (); - void addSectionTitle (const QString&); - void addSectionTitle (QWidget*); - void addSectionTitle (QLayout*); - void addWideControl (QLayout *); - void addWideControl (QWidget *); - QCheckBox* addWideCheckBox (const QString&, bool isChecked); - QLabel* addLabel (const QString&); - QLabel* addTallLabel (const QString&); - void addLabel (QWidget *); - void addTallLabel (QWidget *); - void addControl (QWidget *); - void addControl (QLayout *); - QLabel* addRow (const QString & label, QWidget * control, QWidget * buddy=0); - QLabel* addRow (const QString & label, QLayout * control, QWidget * buddy); - void addRow (QWidget * label, QWidget * control, QWidget * buddy=0); - void addRow (QWidget * label, QLayout * control, QWidget * buddy); - QLabel* addTallRow (const QString & label, QWidget * control, QWidget * buddy=0); - void finish (); - - private: - QLayout* addRow (QWidget* w); - - private: - int myRow; - bool myHasTall; - QGridLayout * myGrid; -}; - -#endif // QTR_HIG_H diff --git a/qt/qtr.pro b/qt/qtr.pro index de1c1dac7..e9edd085e 100644 --- a/qt/qtr.pro +++ b/qt/qtr.pro @@ -52,55 +52,61 @@ TRANSLATIONS += translations/transmission_en.ts \ translations/transmission_uk.ts \ translations/transmission_zh_CN.ts -FORMS += about.ui \ - details.ui \ - mainwin.ui \ - make-dialog.ui \ - make-progress-dialog.ui \ - options.ui \ - prefs-dialog.ui \ - relocate.ui \ - session-dialog.ui \ - stats-dialog.ui +FORMS += AboutDialog.ui \ + DetailsDialog.ui \ + MainWindow.ui \ + MakeDialog.ui \ + MakeProgressDialog.ui \ + OptionsDialog.ui \ + PrefsDialog.ui \ + RelocateDialog.ui \ + SessionDialog.ui \ + StatsDialog.ui RESOURCES += application.qrc win32|macx:RESOURCES += icons/Faenza/Faenza.qrc -SOURCES += about.cc \ - add-data.cc \ - app.cc \ - column-resizer.cc \ - dbus-adaptor.cc \ - details.cc \ - favicon.cc \ - file-tree.cc \ - filterbar.cc \ - filters.cc \ - freespace-label.cc \ - formatter.cc \ - hig.cc \ - license.cc \ - mainwin.cc \ - make-dialog.cc \ - options.cc \ - path-button.cc \ - prefs.cc \ - prefs-dialog.cc \ - relocate.cc \ - rpc-client.cc \ - session.cc \ - session-dialog.cc \ - squeezelabel.cc \ - stats-dialog.cc \ - torrent.cc torrent-delegate.cc \ - torrent-delegate-min.cc \ - torrent-filter.cc \ - torrent-model.cc \ - tracker-delegate.cc \ - tracker-model.cc \ - tracker-model-filter.cc \ - tricontoolbutton.cc \ - utils.cc \ - watchdir.cc +SOURCES += AboutDialog.cc \ + AddData.cc \ + Application.cc \ + ColumnResizer.cc \ + DBusAdaptor.cc \ + DetailsDialog.cc \ + FaviconCache.cc \ + FileTreeDelegate.cc \ + FileTreeItem.cc \ + FileTreeModel.cc \ + FileTreeView.cc \ + FilterBar.cc \ + FilterBarComboBox.cc \ + FilterBarComboBoxDelegate.cc \ + FilterBarLineEdit.cc \ + Filters.cc \ + Formatter.cc \ + FreeSpaceLabel.cc \ + IconToolButton.cc \ + LicenseDialog.cc \ + MainWindow.cc \ + MakeDialog.cc \ + OptionsDialog.cc \ + PathButton.cc \ + Prefs.cc \ + PrefsDialog.cc \ + RelocateDialog.cc \ + RpcClient.cc \ + Session.cc \ + SessionDialog.cc \ + SqueezeLabel.cc \ + StatsDialog.cc \ + Torrent.cc \ + TorrentDelegate.cc \ + TorrentDelegateMin.cc \ + TorrentFilter.cc \ + TorrentModel.cc \ + TrackerDelegate.cc \ + TrackerModel.cc \ + TrackerModelFilter.cc \ + Utils.cc \ + WatchDir.cc HEADERS += $$replace(SOURCES, .cc, .h) -HEADERS += speed.h types.h +HEADERS += CustomVariantType.h Speed.h win32:RC_FILE = qtr.rc