- DownloadManager code in place
[qtrapids] / src / gui / MainWindow.cpp
index 7eca355..884ced0 100644 (file)
@@ -27,7 +27,7 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QApplication>
-
+#include <QPluginLoader>
 
 #include "DownloadView.h"
 #include "SeedView.h"
@@ -160,11 +160,38 @@ void MainWindow::addMenuItem(QWidget* widget, PluginWidgetType type)
 {
 }
 
+bool MainWindow::eventRequest(QVariant param, PluginRequest req)
+{
+       if (req == qtrapids::PluginHostInterface::OPEN_FILE) {
+                       QString sourceFile = param.toString();
+                       
+               // Get the source files name from the full path:
+               QFileInfo fInfo(sourceFile);
+               QString targetFile = fInfo.fileName();
+               targetFile = settings_.value("download/directory").toString() + targetFile;
+               
+               // Copy temoporary file to Downloads directory...
+               if (!QFile::copy(sourceFile, targetFile)) {
+                       qDebug() << "File copying failed";
+                       return false;
+               } else {
+                       // If copying was successful, remove the original temporary file.
+                       QFile::remove(sourceFile);
+               }
+                       
+               // ...and start the torrent:
+               on_torrentFileSelected(targetFile);
+       }
+       
+       return true;
+}
+
+
 //=========================== PRIVATE ================================
 
 void MainWindow::LoadPlugins()
 {
-       /// @todo get plugin directory from settings or go through multiple diectories
+       /// @todo get plugin directory from settings or go through multiple directories
        /// Now we only check the application directory
        pluginsDir_ = QDir(qApp->applicationDirPath());
        pluginsDir_.cd("plugins");
@@ -207,7 +234,6 @@ void MainWindow::on_openAction_clicked()
        dialog->setFileMode(QFileDialog::ExistingFile);
        connect(dialog, SIGNAL(fileSelected(const QString&)), this, SLOT(on_torrentFileSelected(const QString&)));
        dialog->show();
-
 }
 
 void MainWindow::on_removeAction_clicked()