- Additional (plugin)tabs closable in MainWindow
authorlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Tue, 24 Nov 2009 09:04:14 +0000 (09:04 +0000)
committerlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Tue, 24 Nov 2009 09:04:14 +0000 (09:04 +0000)
- 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

src/gui/DownloadView.cpp
src/gui/MainWindow.cpp
src/gui/MainWindow.h
src/plugins/PluginInterface.h
src/plugins/searchplugin/SearchPlugin.cpp
src/plugins/searchplugin/SearchPlugin.h

index 03458db..07c8e97 100644 (file)
@@ -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;
                }
 
index e233aee..273aadc 100644 (file)
@@ -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<Alert>)),
                this, SLOT(on_alert(std::auto_ptr<Alert>)));
 
@@ -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
index fcea41d..53fd0af 100644 (file)
@@ -32,6 +32,7 @@ class QTabWidget;
 class DownloadView;
 class SeedView;
 class PreferencesDialog;
+class PluginInterface; 
 
 /**
        @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
@@ -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<QDir> pluginDirs_;
index 1048efd..c89ba22 100644 (file)
@@ -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;
        };
 
index fbc406f..717a6b6 100644 (file)
@@ -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()
index eecabd3..4c62b96 100644 (file)
@@ -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: