From: lvaatamoinen Date: Tue, 24 Nov 2009 09:04:14 +0000 (+0000) Subject: - Additional (plugin)tabs closable in MainWindow X-Git-Url: http://git.maemo.org/git/?p=qtrapids;a=commitdiff_plain;h=1ff0a23bdb48e5c21a26df217de38b02359b3150 - Additional (plugin)tabs closable in MainWindow - Corrected progress indication display bug - Added PluginInterface function to identify plugins at host. git-svn-id: file:///svnroot/qtrapids/trunk@51 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda --- diff --git a/src/gui/DownloadView.cpp b/src/gui/DownloadView.cpp index 03458db..07c8e97 100644 --- a/src/gui/DownloadView.cpp +++ b/src/gui/DownloadView.cpp @@ -57,7 +57,7 @@ void DownloadView::newItem(qtrapids::QTorrentHandle handle) << handle.name() << QString::number(handle.getTotalSize()) << GetStatusString(handle.state()) - << QString::number(100*handle.progress() + '%') + << QString::number(100*handle.progress()) << QString::number(handle.downloadRate(), 'f', 2) << QString::number(handle.uploadRate(), 'f', 2) << QString::number(handle.numSeeds()) + "/" @@ -100,7 +100,7 @@ void DownloadView::updateItem(qtrapids::QTorrentHandle handle) float prog = handle.progress(); if ((prog-lastProg) >= 0.01 || prog >= 1.0) { item->setData(3, Qt::DisplayRole, - QVariant(QString::number(100*prog) + '%')); + QVariant(QString::number(100*prog))); lastProg = prog; } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index e233aee..273aadc 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -51,6 +51,7 @@ MainWindow::MainWindow(): tabWidget_(NULL), dlView_(NULL), seedView_(NULL), + searchWidget_(NULL), preferencesDialog_(NULL), settings_(), pluginDirs_(), @@ -112,7 +113,8 @@ MainWindow::MainWindow(): SLOT(setEnabled(bool))); connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*))); - + connect (tabWidget_, SIGNAL(tabCloseRequested(int)), this, SLOT(on_tabWidget_tabCloseRequested(int))); + connect(&btSession_, SIGNAL(alert(std::auto_ptr)), this, SLOT(on_alert(std::auto_ptr))); @@ -125,16 +127,24 @@ MainWindow::~MainWindow() } // ===================== Implements PluginInterface ========================= -bool MainWindow::setGui(QWidget* widget, PluginWidgetType type) +/// @todo add PluginInterface parameter to request plugin name +bool MainWindow::setGui(QWidget* widget, PluginWidgetType type, qtrapids::PluginInterface* plugin) { #ifdef QTRAPIDS_DEBUG qDebug() << "MainWindow::setGui():" << dlView_->currentItem(); #endif + + if (plugin && plugin->identifier() == "SearchPlugin") { + searchWidget_ = widget; + } else { + return false; + } + tabWidget_->addTab(widget, tr("Search")); return true; } -/// @todo Add PluginInterface parameter check which plugin gives the widget to handle appropriately +/// @todo Add PluginInterface parameter to check which plugin gives the widget, to handle appropriately void MainWindow::addPluginWidget(QWidget* widget, PluginWidgetType type) { #ifdef QTRAPIDS_DEBUG @@ -142,7 +152,7 @@ void MainWindow::addPluginWidget(QWidget* widget, PluginWidgetType type) #endif if (type == qtrapids::PluginHostInterface::TAB_PAGE) { - int index = tabWidget_->addTab(widget, tr("Test")); + int index = tabWidget_->addTab(widget, tr("Results")); tabWidget_->setCurrentIndex(index); //layout_->addWidget(widget); } @@ -279,7 +289,7 @@ void MainWindow::StartTorrentFromBufferData(char const* data, int size) #endif } -// =========================== SLOTS ================================= +// =========================== PRIVATE SLOTS ================================= void MainWindow::on_openAction_clicked() { QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)")); @@ -294,11 +304,13 @@ void MainWindow::on_removeAction_clicked() btSession_.removeTorrent(handle); } + void MainWindow::on_quitAction_clicked() { close(); } + void MainWindow::on_preferencesAction_clicked() { if (!preferencesDialog_) { @@ -309,6 +321,7 @@ void MainWindow::on_preferencesAction_clicked() preferencesDialog_->activateWindow(); } + void MainWindow::on_aboutAction_clicked() { QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT); @@ -321,6 +334,22 @@ void MainWindow::on_aboutQtAction_clicked() } +void MainWindow::on_tabWidget_tabCloseRequested(int index) +{ + + int searchWidgetIndex = tabWidget_->indexOf(searchWidget_); + + // Allow closing other tabs than the first two + // TODO The first two may well be closable, just add "show tabs" action for these in the menu + if (index != 0 && index != 1 && index != searchWidgetIndex) { + QWidget *remove = tabWidget_->widget(index); + tabWidget_->removeTab(index); + delete remove; + remove = NULL; + } +} + + void MainWindow::on_downloadItemSelectionChanged() { #ifdef QTRAPIDS_DEBUG @@ -333,6 +362,7 @@ void MainWindow::on_downloadItemSelectionChanged() } } + void MainWindow::on_seedItemSelectionChanged() { #ifdef QTRAPIDS_DEBUG @@ -345,6 +375,7 @@ void MainWindow::on_seedItemSelectionChanged() } } + void MainWindow::handleToolBarAction(QAction* action) { if (action->text() == "Open") { @@ -354,6 +385,7 @@ void MainWindow::handleToolBarAction(QAction* action) } } + void MainWindow::on_torrentFileSelected(const QString& file) { #ifdef QTRAPIDS_DEBUG diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index fcea41d..53fd0af 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -32,6 +32,7 @@ class QTabWidget; class DownloadView; class SeedView; class PreferencesDialog; +class PluginInterface; /** @author Lassi Väätämöinen @@ -45,7 +46,7 @@ class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface { virtual ~MainWindow(); // Implemented from PluginHostInterface - virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE); + virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE, qtrapids::PluginInterface* plugin = NULL); virtual void addPluginWidget(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE); virtual void addToolbar(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE); virtual void addToolItem(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE); @@ -64,6 +65,7 @@ class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface { void on_preferencesAction_clicked(); void on_aboutAction_clicked(); void on_aboutQtAction_clicked(); + void on_tabWidget_tabCloseRequested(int index); void on_downloadItemSelectionChanged(); void on_seedItemSelectionChanged(); void handleToolBarAction(QAction* action); @@ -78,6 +80,7 @@ class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface { QTabWidget *tabWidget_; DownloadView *dlView_; SeedView *seedView_; + QWidget *searchWidget_; PreferencesDialog *preferencesDialog_; QSettings settings_; QList pluginDirs_; diff --git a/src/plugins/PluginInterface.h b/src/plugins/PluginInterface.h index 1048efd..c89ba22 100644 --- a/src/plugins/PluginInterface.h +++ b/src/plugins/PluginInterface.h @@ -63,7 +63,7 @@ namespace qtrapids /// @brief Sets the plugin GUI element to host application /// @note It is up to the host application to decide how to manage /// and show the actual widget. - virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE) = 0; + virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN_TYPE, PluginInterface* plugin = NULL) = 0; /// @brief Adds additional plugin wigdets to the host application. /// This functio can be called by the plugin recursively, i.e. when GUI events occur @@ -103,6 +103,11 @@ namespace qtrapids /// @brief Initializes the plugin instance. virtual void initialize(PluginHostInterface* host, Info info = Info()) = 0; + + /// @brief Returns plugin identifier to be used by the host application + /// @returns Plugin identifier as string representation. + virtual QString identifier() = 0; + virtual QWidget* getGui() = 0; }; diff --git a/src/plugins/searchplugin/SearchPlugin.cpp b/src/plugins/searchplugin/SearchPlugin.cpp index fbc406f..717a6b6 100644 --- a/src/plugins/searchplugin/SearchPlugin.cpp +++ b/src/plugins/searchplugin/SearchPlugin.cpp @@ -41,7 +41,7 @@ namespace qtrapids const QString ENGINES_DIR = "engines"; const QString DESCRIPTION_FILENAME = "opensearch.xml"; const QString SEARCH_TERMS_STRING = "{searchTerms}"; - + const QString SEARCHPLUGIN_ID = "SearchPlugin"; SearchPlugin::SearchPlugin() : comboBox_(NULL), searchLine_(NULL), @@ -80,7 +80,7 @@ namespace qtrapids ParseSearchEngineDescriptions(dir); } - host_->setGui(pluginWidget, qtrapids::PluginHostInterface::BASE_WIDGET); + host_->setGui(pluginWidget, qtrapids::PluginHostInterface::BASE_WIDGET, this); } } @@ -88,6 +88,11 @@ namespace qtrapids { return NULL; } + + QString SearchPlugin::identifier() + { + return SEARCHPLUGIN_ID; + } void SearchPlugin::on_searchButton_clicked() diff --git a/src/plugins/searchplugin/SearchPlugin.h b/src/plugins/searchplugin/SearchPlugin.h index eecabd3..4c62b96 100644 --- a/src/plugins/searchplugin/SearchPlugin.h +++ b/src/plugins/searchplugin/SearchPlugin.h @@ -48,6 +48,7 @@ class SearchPlugin : public PluginInterface /// @brief Initializes the SearchPlugin /// @param info info.directory is used to search for searchengine description files. virtual void initialize(PluginHostInterface* host, Info info); + virtual QString identifier(); virtual QWidget* getGui(); signals: