From: lvaatamoinen Date: Wed, 18 Nov 2009 10:12:38 +0000 (+0000) Subject: -Code formatted using script X-Git-Url: http://git.maemo.org/git/?p=qtrapids;a=commitdiff_plain;h=ddbc718c23dac010160c4dc07b655608c3ab3ab2 -Code formatted using script git-svn-id: file:///svnroot/qtrapids/trunk@33 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda --- diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 4c8cc19..549fb8d 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -35,13 +35,13 @@ #include "MainWindow.h" -const QString ABOUT_TEXT - = QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on" - "\nQt and Libtorrent." - "\n\nURL: http://qtrapids.garage.maemo.org/" - "\n\nAuthors:\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com" - "\nDenis Zalevskiy, denis.zalewsky@ixonos.com" - "\n\nIxonos Plc, Finland\n")); +const QString ABOUT_TEXT += QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on" + "\nQt and Libtorrent." + "\n\nURL: http://qtrapids.garage.maemo.org/" + "\n\nAuthors:\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com" + "\nDenis Zalevskiy, denis.zalewsky@ixonos.com" + "\n\nIxonos Plc, Finland\n")); // Consturctor MainWindow::MainWindow(): @@ -54,66 +54,66 @@ MainWindow::MainWindow(): // torrentHandles_(), btSession_() { - // MENUBAR - QMenuBar *menuBar = new QMenuBar(); - QMenu *tempMenu = NULL; - - tempMenu = menuBar->addMenu(tr("&File")); - QAction *openAction = tempMenu->addAction(tr("&Open")); - QAction *removeAction = tempMenu->addAction(tr("&Remove")); - removeAction->setEnabled(false); - QAction *quitAction = tempMenu->addAction(tr("&Quit")); - - tempMenu = menuBar->addMenu(tr("&Settings")); - QAction *preferencesAction = tempMenu->addAction(tr("&Preferences")); - - tempMenu = menuBar->addMenu(tr("&Help")); - QAction *aboutAction = tempMenu->addAction(tr("&About")); - QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt")); - - setMenuBar(menuBar); - connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked())); - connect(removeAction, SIGNAL(triggered()), this, SLOT(on_removeAction_clicked())); - connect(this, SIGNAL(itemSelected(bool)), removeAction, SLOT(setEnabled(bool))); - connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked())); - connect(preferencesAction, SIGNAL(triggered()), this, SLOT(on_preferencesAction_clicked())); - connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked())); - connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked())); - - // TABWIDGET (central widget) - tabWidget_ = new QTabWidget(); - tabWidget_->setTabsClosable(true); - - /// @todo Exception handling - dlView_ = new DownloadView(this); - seedView_ = new SeedView(this); - tabWidget_->addTab(dlView_, tr("Downloads")); - tabWidget_->addTab(seedView_, tr("Seeds")); - connect(dlView_, SIGNAL(itemSelectionChanged()), this, - SLOT(on_downloadItemSelectionChanged())); - connect(seedView_, SIGNAL(itemSelectionChanged()), this, - SLOT(on_seedItemSelectionChanged())); - - - // Tab widget as central widget. - setCentralWidget(tabWidget_); - - // TOOLBAR - QToolBar *toolBar = new QToolBar(); - toolBar->addAction(tr("Open")); - removeAction = toolBar->addAction(tr("Remove")); - removeAction->setEnabled(false); - addToolBar(Qt::TopToolBarArea, toolBar); - - connect(this, SIGNAL(itemSelected(bool)), removeAction, - SLOT(setEnabled(bool))); - connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, - SLOT(handleToolBarAction(QAction*))); - - connect(&btSession_, SIGNAL(alert(std::auto_ptr)), - this, SLOT(on_alert(std::auto_ptr))); - - LoadPlugins(); + // MENUBAR + QMenuBar *menuBar = new QMenuBar(); + QMenu *tempMenu = NULL; + + tempMenu = menuBar->addMenu(tr("&File")); + QAction *openAction = tempMenu->addAction(tr("&Open")); + QAction *removeAction = tempMenu->addAction(tr("&Remove")); + removeAction->setEnabled(false); + QAction *quitAction = tempMenu->addAction(tr("&Quit")); + + tempMenu = menuBar->addMenu(tr("&Settings")); + QAction *preferencesAction = tempMenu->addAction(tr("&Preferences")); + + tempMenu = menuBar->addMenu(tr("&Help")); + QAction *aboutAction = tempMenu->addAction(tr("&About")); + QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt")); + + setMenuBar(menuBar); + connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked())); + connect(removeAction, SIGNAL(triggered()), this, SLOT(on_removeAction_clicked())); + connect(this, SIGNAL(itemSelected(bool)), removeAction, SLOT(setEnabled(bool))); + connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked())); + connect(preferencesAction, SIGNAL(triggered()), this, SLOT(on_preferencesAction_clicked())); + connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked())); + connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked())); + + // TABWIDGET (central widget) + tabWidget_ = new QTabWidget(); + tabWidget_->setTabsClosable(true); + + /// @todo Exception handling + dlView_ = new DownloadView(this); + seedView_ = new SeedView(this); + tabWidget_->addTab(dlView_, tr("Downloads")); + tabWidget_->addTab(seedView_, tr("Seeds")); + connect(dlView_, SIGNAL(itemSelectionChanged()), this, + SLOT(on_downloadItemSelectionChanged())); + connect(seedView_, SIGNAL(itemSelectionChanged()), this, + SLOT(on_seedItemSelectionChanged())); + + + // Tab widget as central widget. + setCentralWidget(tabWidget_); + + // TOOLBAR + QToolBar *toolBar = new QToolBar(); + toolBar->addAction(tr("Open")); + removeAction = toolBar->addAction(tr("Remove")); + removeAction->setEnabled(false); + addToolBar(Qt::TopToolBarArea, toolBar); + + connect(this, SIGNAL(itemSelected(bool)), removeAction, + SLOT(setEnabled(bool))); + connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, + SLOT(handleToolBarAction(QAction*))); + + connect(&btSession_, SIGNAL(alert(std::auto_ptr)), + this, SLOT(on_alert(std::auto_ptr))); + + LoadPlugins(); } @@ -125,22 +125,22 @@ MainWindow::~MainWindow() bool MainWindow::setGui(qtrapids::PluginInterface* from, QWidget* widget) { #ifdef QTRAPIDS_DEBUG - qDebug() << "MainWindow::setGui():" << dlView_->currentItem(); + qDebug() << "MainWindow::setGui():" << dlView_->currentItem(); #endif - tabWidget_->addTab(widget, tr("Search")); - return true; + tabWidget_->addTab(widget, tr("Search")); + return true; } /// @todo Add PluginInterface parameter check which plugin gives the widget to handle appropriately void MainWindow::addPluginWidget(qtrapids::PluginInterface* from, QWidget* widget) { #ifdef QTRAPIDS_DEBUG - qDebug() << "MainWindow::addPluginWidget():" << dlView_->currentItem(); + qDebug() << "MainWindow::addPluginWidget():" << dlView_->currentItem(); #endif - - int index = tabWidget_->addTab(widget, tr("Test")); - tabWidget_->setCurrentIndex(index); - //layout_->addWidget(widget); + + int index = tabWidget_->addTab(widget, tr("Test")); + tabWidget_->setCurrentIndex(index); + //layout_->addWidget(widget); } void MainWindow::addToolbar(qtrapids::PluginInterface* from, QWidget* widget) @@ -163,52 +163,61 @@ void MainWindow::addMenuItem(qtrapids::PluginInterface* from, QWidget* widget) void MainWindow::LoadPlugins() { - /// @todo get plugin directory from settings or go through multiple diectories - /// Now we only check the application directory - pluginsDir_ = QDir(qApp->applicationDirPath()); - pluginsDir_.cd("plugins"); - QStringList nameFilters; - nameFilters << "*.so"; - - foreach (QString fileName, pluginsDir_.entryList(nameFilters, QDir::Files)) { - QPluginLoader pluginLoader(pluginsDir_.absoluteFilePath(fileName)); - - if (!QLibrary::isLibrary(fileName)) { - qDebug() << fileName << " not a library"; - } - - if (pluginLoader.load()) { - qDebug() << "Plugin loaded: " << fileName; - } else { - qDebug() << "Plugin load failed: " << pluginLoader.errorString(); - } - - QObject *baseInstance = pluginLoader.instance(); - if (!baseInstance) { - qDebug() << "Base instance = NULL."; - } - - qtrapids::PluginInterface *plugin = qobject_cast(baseInstance); - - if (!plugin) { - qDebug() << "Cast failed."; - } else { - plugin->initialize(this); - pluginFileNames_ += fileName; - } - + /// @todo get plugin directory from settings or go through multiple diectories + /// Now we only check the application directory + pluginsDir_ = QDir(qApp->applicationDirPath()); + pluginsDir_.cd("plugins"); + QStringList nameFilters; + nameFilters << "*.so"; + + foreach (QString fileName, pluginsDir_.entryList(nameFilters, QDir::Files)) + { + QPluginLoader pluginLoader(pluginsDir_.absoluteFilePath(fileName)); + + if (!QLibrary::isLibrary(fileName)) + { + qDebug() << fileName << " not a library"; + } + + if (pluginLoader.load()) + { + qDebug() << "Plugin loaded: " << fileName; + } + else + { + qDebug() << "Plugin load failed: " << pluginLoader.errorString(); + } + + QObject *baseInstance = pluginLoader.instance(); + if (!baseInstance) + { + qDebug() << "Base instance = NULL."; + } + + qtrapids::PluginInterface *plugin = qobject_cast(baseInstance); + + if (!plugin) + { + qDebug() << "Cast failed."; + } + else + { + plugin->initialize(this); + pluginFileNames_ += fileName; + } + // QObject *plugin = pluginLoader.instance(); // if (plugin) { // populateMenus(plugin); // pluginFileNames += fileName; // } - } - - //pluginLoader_.setFileName("../libsearchplugin.so"); - + } + + //pluginLoader_.setFileName("../libsearchplugin.so"); + + - } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 9ac916d..a47ca78 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -38,52 +38,52 @@ class PreferencesDialog; */ class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface { - Q_OBJECT - - public: - MainWindow(); + Q_OBJECT + +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 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(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 al); - - private: - void LoadPlugins(); - - private: - QTabWidget *tabWidget_; - DownloadView *dlView_; - SeedView *seedView_; - PreferencesDialog *preferencesDialog_; - QSettings settings_; - QDir pluginsDir_; - QStringList pluginFileNames_; - - qtrapids::QBittorrentSession btSession_; - }; #endif diff --git a/src/plugins/PluginInterface.h b/src/plugins/PluginInterface.h index 0e56353..019dc9a 100644 --- a/src/plugins/PluginInterface.h +++ b/src/plugins/PluginInterface.h @@ -26,50 +26,51 @@ 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 - -======= + +// 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 +* @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 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 + >>>>>>> .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. diff --git a/src/plugins/searchplugin/SearchPlugin.cpp b/src/plugins/searchplugin/SearchPlugin.cpp index 10165f0..65f3b89 100644 --- a/src/plugins/searchplugin/SearchPlugin.cpp +++ b/src/plugins/searchplugin/SearchPlugin.cpp @@ -34,72 +34,74 @@ namespace qtrapids { <<<<<<< .mine - 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); - } - } - - 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); - } - } -======= 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(this, pluginWidget); + } +} + +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); + } +} +======= + SearchPlugin::SearchPlugin() : + comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL) +{ + // TODO: Parse engine descriptions. + // -Add engines to model + // -Show model in comboBox + >>>>>>> .r31 }