- Search plugin interface changed: enum constants to define widget types to allow...
authorlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Wed, 18 Nov 2009 12:59:31 +0000 (12:59 +0000)
committerlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Wed, 18 Nov 2009 12:59:31 +0000 (12:59 +0000)
git-svn-id: file:///svnroot/qtrapids/trunk@38 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda

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

index 2425ffc..7eca355 100644 (file)
@@ -122,7 +122,7 @@ MainWindow::~MainWindow()
 }
 
 // ===================== Implements PluginInterface =========================
-bool MainWindow::setGui(qtrapids::PluginInterface* from, QWidget* widget)
+bool MainWindow::setGui(QWidget* widget, PluginWidgetType type)
 {
 #ifdef QTRAPIDS_DEBUG
        qDebug() << "MainWindow::setGui():" << dlView_->currentItem();
@@ -132,30 +132,31 @@ bool MainWindow::setGui(qtrapids::PluginInterface* from, QWidget* widget)
 }
 
 /// @todo Add PluginInterface parameter check which plugin gives the widget to handle appropriately
-void MainWindow::addPluginWidget(qtrapids::PluginInterface* from, QWidget* widget)
+void MainWindow::addPluginWidget(QWidget* widget, PluginWidgetType type)
 {
 #ifdef QTRAPIDS_DEBUG
        qDebug() << "MainWindow::addPluginWidget():" << dlView_->currentItem();
 #endif
 
-       int index = tabWidget_->addTab(widget, tr("Test"));
-       tabWidget_->setCurrentIndex(index);
-       //layout_->addWidget(widget);
+       if (type == qtrapids::PluginHostInterface::TAB_PAGE) {
+               int index = tabWidget_->addTab(widget, tr("Test"));
+               tabWidget_->setCurrentIndex(index);
+               //layout_->addWidget(widget);
+       }
 }
-
-void MainWindow::addToolbar(qtrapids::PluginInterface* from, QWidget* widget)
+void MainWindow::addToolbar(QWidget* widget, PluginWidgetType type)
 {
 }
 
-void MainWindow::addToolItem(qtrapids::PluginInterface* from, QWidget* widget)
+void MainWindow::addToolItem(QWidget* widget, PluginWidgetType type)
 {
 }
 
-void MainWindow::addMenu(qtrapids::PluginInterface* from, QWidget* widget)
+void MainWindow::addMenu(QWidget* widget, PluginWidgetType type)
 {
 }
 
-void MainWindow::addMenuItem(qtrapids::PluginInterface* from, QWidget* widget)
+void MainWindow::addMenuItem(QWidget* widget, PluginWidgetType type)
 {
 }
 
@@ -196,20 +197,7 @@ void MainWindow::LoadPlugins()
                        plugin->initialize(this);
                        pluginFileNames_ += fileName;
                }
-
-//             QObject *plugin = pluginLoader.instance();
-//             if (plugin) {
-//                             populateMenus(plugin);
-//                             pluginFileNames += fileName;
-//             }
-
        }
-
-       //pluginLoader_.setFileName("../libsearchplugin.so");
-
-
-
-
 }
 
 // =========================== SLOTS =================================
@@ -338,7 +326,7 @@ void MainWindow::on_alert(std::auto_ptr<Alert> al)
 bool MainWindow::IsNewTorrent(std::auto_ptr<qtrapids::QTorrentHandle> handlePtr)
 {
        for (unsigned i = 0; i < torrentHandles_.size(); ++i) {
-               if (torrentHandles_.at(i).get() == handlePtr.get()) {
+    if (torrentHandles_.at(i).get() == handlePtr.get()) {
                        return false;
                } else {
                        return true;
index 8dd1fdc..715ce23 100644 (file)
@@ -36,54 +36,56 @@ class PreferencesDialog;
 /**
        @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
 */
-class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface
-{
+class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface {
        Q_OBJECT
+                       
+       public:
+    MainWindow();
 
-public:
-       MainWindow();
-
-       virtual ~MainWindow();
-
-       // Implemented from PluginHostInterface
-       virtual bool setGui(qtrapids::PluginInterface* from, QWidget* widget);
-       virtual void addPluginWidget(qtrapids::PluginInterface* from, QWidget* widget);
-       virtual void addToolbar(qtrapids::PluginInterface* from, QWidget* widget);
-       virtual void addToolItem(qtrapids::PluginInterface* from, QWidget* widget);
-       virtual void addMenu(qtrapids::PluginInterface* from, QWidget* widget);
-       virtual void addMenuItem(qtrapids::PluginInterface* from, QWidget* widget);
-
-signals:
-       void itemSelected(bool enabled);
-
-public slots:
-private slots:
-       void on_openAction_clicked();
-       void on_removeAction_clicked();
-       void on_quitAction_clicked();
-       void on_preferencesAction_clicked();
-       void on_aboutAction_clicked();
-       void on_aboutQtAction_clicked();
-       void on_downloadItemSelectionChanged();
-       void on_seedItemSelectionChanged();
-       void handleToolBarAction(QAction* action);
-       void on_torrentFileSelected(const QString& file);
-       void on_alert(std::auto_ptr<Alert> al);
-
-private:
-       void LoadPlugins();
-
-private:
-       QTabWidget *tabWidget_;
-       DownloadView *dlView_;
-       SeedView *seedView_;
-       PreferencesDialog *preferencesDialog_;
-       QSettings settings_;
-       QDir pluginsDir_;
-       QStringList pluginFileNames_;
-
-       qtrapids::QBittorrentSession btSession_;
+    virtual ~MainWindow();
+               
+               // Implemented from PluginHostInterface
+               virtual bool setGui(QWidget* widget, PluginWidgetType type = UNKNOWN);
+               virtual void addPluginWidget(QWidget* widget, PluginWidgetType type = UNKNOWN);
+               virtual void addToolbar(QWidget* widget, PluginWidgetType type = UNKNOWN);
+               virtual void addToolItem(QWidget* widget, PluginWidgetType type = UNKNOWN);
+               virtual void addMenu(QWidget* widget, PluginWidgetType type = UNKNOWN);
+               virtual void addMenuItem(QWidget* widget, PluginWidgetType type = UNKNOWN);
+               
+       signals:
+               void itemSelected(bool enabled);
+               
+       public slots:
+       private slots:
+               void on_openAction_clicked();
+               void on_removeAction_clicked();
+               void on_quitAction_clicked();
+               void on_preferencesAction_clicked();
+               void on_aboutAction_clicked();
+               void on_aboutQtAction_clicked();
+               void on_downloadItemSelectionChanged();
+               void on_seedItemSelectionChanged();
+               void handleToolBarAction(QAction* action);
+               void on_torrentFileSelected(const QString& file);
+               void on_alert(std::auto_ptr<Alert> al);
+       
+       private:
+               void LoadPlugins();
+               
+       private:
+               QTabWidget *tabWidget_;
+               DownloadView *dlView_;
+               SeedView *seedView_;
+               PreferencesDialog *preferencesDialog_;
+               QSettings settings_;
+               QDir pluginsDir_;
+               QStringList pluginFileNames_;
+               //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
+               
+               qtrapids::QBittorrentSession btSession_;
+               
 
+               //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
 };
 
 #endif
index 427c330..33cd491 100644 (file)
 
 namespace qtrapids
 {
-<<<<<<< .mine
-
-// Forward declaration because of co-dependency of classes.
-class PluginInterface;
-
-/** @class PluginHostInterface
-* @brief Defines interface for plugins to access the host application.
-* A Host is an application that is extended by implementing Plugins,
-* that implement the additional functionality
-* @note Implementing plugin host should inherit QObject.
-*/
-class PluginHostInterface
-{
-public:
-
-       /// @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(PluginInterface* from, QWidget* widget) = 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
-       /// The host application must handle placing the additional widgets.
-       /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
-       virtual void addPluginWidget(PluginInterface* from, QWidget* widget) = 0;
-       virtual void addToolbar(PluginInterface* from, QWidget* widget) = 0;
-       virtual void addToolItem(PluginInterface* from, QWidget* widget) = 0;
-       virtual void addMenu(PluginInterface* from, QWidget* widget) = 0;
-       virtual void addMenuItem(PluginInterface* from, QWidget* widget) = 0;
-};
-=======
-    >>>>>>> .r31
-    <<<<<<< .mine
-
-    =======
-
-        /** @class PluginHostInterface
-               * @brief Defines interface for plugins to access the host application.
-               * A Host is an application that is extended by implementing Plugins,
-               * that implement the additional functionality
-        */
-        class PluginHostInterface : public QObject
-{
-public:
-
-       >>>>>>> .r31
-       /// @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) = 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
-       /// The host application must handle placing the additional widgets.
-       /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
-       virtual void addPluginWidget(QWidget* widget) = 0;
-       virtual void addToolbar() = 0;
-       virtual void addToolItem() = 0;
-       virtual void addMenu() = 0;
-       virtual void addMenuItem() = 0;
-};
-
-
-/** @class PluginInterface
-       * @brief Defines interface for a plugin instance.
-       * The host application uses PluginInterface interface for calling the plugins
-       * that extend the Host functionality
-*/
-class PluginInterface : public QObject
-{
-public:
-       /// @brief Initializes the plugin instance.
-       virtual void initialize(PluginHostInterface* host) = 0;
-       virtual QWidget* getGui() = 0;
-};
+       
+               // Forward declaration because of co-dependency of classes.
+               class PluginInterface;
+       
+
+               /** @class PluginHostInterface
+               * @brief Defines interface for plugins to access the host application. 
+               * A Host is an application that is extended by implementing Plugins, 
+               * that implement the additional functionality
+               * @note Implementing plugin host should inherit QObject.
+       */
+       class PluginHostInterface {
+               public:
+                       /// @enum PluginWidgetType Allows plugin host to differentiate actions 
+                       /// when passed as parameter to addWidget(). E.g. Popup a dialog or append tab etc.
+                       /// @todo add new types
+                       enum PluginWidgetType {
+                               BASE_WIDGET,
+                               TAB_PAGE,
+                               UNKNOWN
+                       };
+                       
+                       /// @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) = 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
+                       /// The host application must handle placing the additional widgets.
+                       /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
+                       virtual void addPluginWidget(QWidget* widget, PluginWidgetType type = UNKNOWN) = 0;
+                       virtual void addToolbar(QWidget* widget, PluginWidgetType type = UNKNOWN) = 0;
+                       virtual void addToolItem(QWidget* widget, PluginWidgetType type = UNKNOWN) = 0;
+                       virtual void addMenu(QWidget* widget, PluginWidgetType type = UNKNOWN) = 0;
+                       virtual void addMenuItem(QWidget* widget, PluginWidgetType type = UNKNOWN) = 0;
+       };
+  
+  
+  
+       /** @class PluginInterface 
+               * @brief Defines interface for a plugin instance.
+               * The host application uses PluginInterface interface for calling the plugins
+               * that extend the Host functionality
+       */
+       class PluginInterface : public QObject {
+               public:
+                       /// @brief Initializes the plugin instance.
+                       virtual void initialize(PluginHostInterface* host) = 0;
+                       virtual QWidget* getGui() = 0;
+       };
 
 } //namespace qtrapids
 
@@ -109,59 +85,59 @@ Q_DECLARE_INTERFACE(qtrapids::PluginInterface,
                     "com.ixonos.qtrapids.PluginInterface/1.0")
 Q_DECLARE_INTERFACE(qtrapids::PluginHostInterface,
                     "com.ixonos.qtrapids.PluginHostInterface/1.0")
-
-
+                                                                               
+                                                                               
 //////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
 // A simple plugin example using the PluginInterface
 // For more info, see Qt documentation: "How to Create Qt Plugins"
 //
 // namespace qtrapids
 // {
-//
+// 
 //     class MyPlugin : public PluginInterface {
 //             Q_OBJECT
 //             // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
 //             Q_INTERFACES(qtrapids::PluginInterface)
-//
+//             
 //             public:
 //                     MyPlugin();
 //                     virtual void initialize(PluginHostInterface* host);
 //                     virtual QWidget* getGui();
-//
+//             
 // // Additional plugin-specific signals and slots.
-//             signals:
+//             signals: 
 //                     void searchResult(QWidget* resultwidget);
-//
-//             private slots:
+//                     
+//             private slots: 
 //                     void on_button_clicked();
 //                     void on_result(QWidget* resultWidget);
-//
+//                     
 //             private:
 //     };
-//
+// 
 //
 //     MyPlugin::MyPlugin(): host_(NULL) {}
-//
+// 
 //             void SearchPlugin::initialize(AbstractPluginHost* host)
 //             {
 //                     host_ = host;
-//
+//                     
 //                     if (host_ != NULL) {
 //                             QWidget *pluginWidget = new QWidget;
 //                             QVBoxLayout *vbox = new QVBoxLayout;
 //                             QPushButton *searchButton = new QPushButton("Search");
 //                             vbox->addWidget(searchButton);
 //                             pluginWidget->setLayout(vbox);
-//
+//             
 //                             connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
 //                             //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
-//
-//                             // Call host interface function to set the plugin GUI. Host handles the setup
+//                             
+//                             // Call host interface function to set the plugin GUI. Host handles the setup 
 //                             // to it's own policy
 //                             host_->setGui(pluginWidget);
 //                     }
 //             }
-// } // namespace qtrapids
+// } // namespace qtrapids 
 //
 //// NOTE: Remember to export the actual plugin to be visible for Qt:
 //// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
index 8c6aac4..27417f1 100644 (file)
 
 namespace qtrapids
 {
-<<<<<<< .mine
-SearchPlugin::SearchPlugin() :
+       SearchPlugin::SearchPlugin() : 
                comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL)
-{
-       // TODO: Parse engine descriptions.
-       // -Add engines to model
-       // -Show model in comboBox
-
-}
-
-void SearchPlugin::initialize(PluginHostInterface* host)
-{
-       host_ = host;
-
-       if (host_ != NULL) {
-
-               QWidget *pluginWidget = new QWidget;
-               QVBoxLayout *vbox = new QVBoxLayout;
-               QHBoxLayout *hbox = new QHBoxLayout;
-               comboBox_ = new QComboBox;
-               searchLine_ = new QLineEdit;
-               searchButton_ = new QPushButton("Search");
-
-               hbox->addWidget(searchLine_);
-               hbox->addWidget(searchButton_);
-               vbox->addWidget(comboBox_);
-               vbox->addLayout(hbox);
-               pluginWidget->setLayout(vbox);
-
-               connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
-               //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
-
-               host_->setGui(this, pluginWidget);
+       {
+               // TODO: Parse engine descriptions.
+               // -Add engines to model
+               // -Show model in comboBox
+       
        }
-}
-
-QWidget* SearchPlugin::getGui()
-{
-       return NULL;
-}
-
-void SearchPlugin::on_searchButton_clicked()
-{
-       QUrl searchUrl(QString("http://www.google.fi/search?q="
-                              + searchLine_->text()));
-       qDebug() << searchUrl;
-       QWebView *result = new QWebView;
-       result->load(searchUrl);
-
-       on_searchResult((QWidget*)result);
-}
-
-void SearchPlugin::on_searchResult(QWidget* resultWidget)
-{
-       qDebug() << "on_searchResult()";
-       if (host_) {
-               host_->addPluginWidget(this, resultWidget);
+       
+       void SearchPlugin::initialize(PluginHostInterface* host)
+       {
+               host_ = host;
+               
+               if (host_ != NULL) {
+                       
+                       QWidget *pluginWidget = new QWidget;
+                       QVBoxLayout *vbox = new QVBoxLayout;
+                       QHBoxLayout *hbox = new QHBoxLayout;
+                       comboBox_ = new QComboBox;
+                       searchLine_ = new QLineEdit;
+                       searchButton_ = new QPushButton("Search");
+                       
+                       hbox->addWidget(searchLine_);
+                       hbox->addWidget(searchButton_);
+                       vbox->addWidget(comboBox_);
+                       vbox->addLayout(hbox);
+                       pluginWidget->setLayout(vbox);
+       
+                       connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
+                       //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
+                       
+                       host_->setGui(pluginWidget, qtrapids::PluginHostInterface::BASE_WIDGET);
+               }
        }
-}
-=======
-    SearchPlugin::SearchPlugin() :
-                   comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL)
-{
-       // TODO: Parse engine descriptions.
-       // -Add engines to model
-       // -Show model in comboBox
-       >>>>>>> .r31
-
-}
-
-void SearchPlugin::initialize(PluginHostInterface* host)
-{
-       host_ = host;
-
-       if (host_ != NULL) {
-
-               QWidget *pluginWidget = new QWidget;
-               QVBoxLayout *vbox = new QVBoxLayout;
-               QHBoxLayout *hbox = new QHBoxLayout;
-               comboBox_ = new QComboBox;
-               searchLine_ = new QLineEdit;
-               searchButton_ = new QPushButton("Search");
-
-               hbox->addWidget(searchLine_);
-               hbox->addWidget(searchButton_);
-               vbox->addWidget(comboBox_);
-               vbox->addLayout(hbox);
-               pluginWidget->setLayout(vbox);
-
-               connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
-               //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
-
-               host_->setGui(pluginWidget);
+       
+       QWidget* SearchPlugin::getGui()
+       {
+               return NULL;
        }
-}
-
-QWidget* SearchPlugin::getGui()
-{
-       return NULL;
-}
-
-void SearchPlugin::on_searchButton_clicked()
-{
-       QUrl searchUrl(QString("http://www.google.fi/search?q="
-                              + searchLine_->text()));
-       qDebug() << searchUrl;
-       QWebView *result = new QWebView;
-       result->load(searchUrl);
-
-       on_searchResult((QWidget*)result);
-}
-
-void SearchPlugin::on_searchResult(QWidget* resultWidget)
-{
-       qDebug() << "on_searchResult()";
-       if (host_) {
-               host_->addPluginWidget(resultWidget);
+       
+       void SearchPlugin::on_searchButton_clicked()
+       {
+               QUrl searchUrl(QString("http://www.google.fi/search?q="
+                       + searchLine_->text()));
+               qDebug() << searchUrl;
+               QWebView *result = new QWebView;
+               result->load(searchUrl);
+               
+               on_searchResult((QWidget*)result);
+       }
+       
+       void SearchPlugin::on_searchResult(QWidget* resultWidget)
+       {
+               qDebug() << "on_searchResult()";
+               if (host_) {
+                       host_->addPluginWidget(resultWidget, qtrapids::PluginHostInterface::TAB_PAGE);
+               }
        }
-}
 
 } // namespace qtrapids