void TorrentModel::populate() { // Load the torrents std::vector<Transfer> torrents = Session::instance()->getTransfers(); std::vector<Transfer>::const_iterator it; for (it = torrents.begin(); it != torrents.end(); it++) { addTorrent(*it); } // Refresh timer connect(&m_refreshTimer, SIGNAL(timeout()), SLOT(forceModelRefresh())); m_refreshTimer.start(m_refreshInterval); // Listen for torrent changes connect(Session::instance(), SIGNAL(addedTransfer(Transfer)), SLOT(addTorrent(Transfer))); connect(Session::instance(), SIGNAL(transferAboutToBeRemoved(Transfer, bool)), SLOT(handleTorrentAboutToBeRemoved(Transfer, bool))); connect(Session::instance(), SIGNAL(deletedTransfer(QString)), SLOT(removeTorrent(QString))); connect(Session::instance(), SIGNAL(finishedTransfer(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(metadataReceived(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(resumedTransfer(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(pausedTransfer(Transfer)), SLOT(handleTorrentUpdate(Transfer))); connect(Session::instance(), SIGNAL(transferFinishedChecking(Transfer)), SLOT(handleTorrentUpdate(Transfer))); }
// Constructor MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), m_posInitialized(false), force_exit(false), icon_TrayConn(res::trayConnected()), icon_TrayDisconn(res::trayDisconnected()), icon_CurTray(icon_TrayDisconn) { setupUi(this); stackedWidget->addWidget(new transfers_widget(this)); stackedWidget->addWidget(new search_widget(this)); stackedWidget->addWidget(new preferences_widget(this)); stackedWidget->setCurrentIndex(0); setWindowTitle(tr("qDonkey %1").arg(misc::versionString())); QCoreApplication::instance()->installEventFilter(this); //QApplication::setOverrideCursor(Qt::WaitCursor); m_last_file_error = QDateTime::currentDateTime().addSecs(-1); // imagine last file error event was 1 seconds in past #ifdef Q_WS_WIN m_nTaskbarButtonCreated = RegisterWindowMessage(L"TaskbarButtonCreated"); #else m_nTaskbarButtonCreated = 0; #endif Preferences pref; // Clean exit on log out connect(static_cast<SessionApplication*>(qApp), SIGNAL(sessionIsShuttingDown()), this, SLOT(deleteSession())); this->setWindowIcon(QIcon(res::favicon())); #ifdef Q_WS_MAC connect(static_cast<QMacApplication*>(qApp), SIGNAL(newFileOpenMacEvent(QString)), this, SLOT(processParams(QString))); #endif statusBar = new status_bar(this, QMainWindow::statusBar()); m_pwr = new PowerManagement(this); // Configure session according to options loadPreferences(false); // Start connection checking timer guiUpdater = new QTimer(this); connect(guiUpdater, SIGNAL(timeout()), this, SLOT(updateGUI())); guiUpdater->start(2000); // Accept drag 'n drops //setAcceptDrops(true); createKeyboardShortcuts(); #ifdef Q_WS_MAC setUnifiedTitleAndToolBarOnMac(true); #endif // View settings // Auto shutdown actions /* QActionGroup * autoShutdownGroup = new QActionGroup(this); autoShutdownGroup->setExclusive(true); autoShutdownGroup->addAction(actionAutoShutdown_Disabled); autoShutdownGroup->addAction(actionAutoExit_mule); autoShutdownGroup->addAction(actionAutoShutdown_system); autoShutdownGroup->addAction(actionAutoSuspend_system); #if !defined(Q_WS_X11) || defined(QT_DBUS_LIB) actionAutoShutdown_system->setChecked(pref.shutdownWhenDownloadsComplete()); actionAutoSuspend_system->setChecked(pref.suspendWhenDownloadsComplete()); #else actionAutoShutdown_system->setDisabled(true); actionAutoSuspend_system->setDisabled(true); #endif actionAutoExit_mule->setChecked(pref.shutdownqBTWhenDownloadsComplete()); if (!autoShutdownGroup->checkedAction()) actionAutoShutdown_Disabled->setChecked(true); */ readSettings(); show(); activateWindow(); raise(); // Start watching the executable for updates executable_watcher = new QFileSystemWatcher(); connect(executable_watcher, SIGNAL(fileChanged(QString)), this, SLOT(notifyOfUpdate(QString))); executable_watcher->addPath(qApp->applicationFilePath()); // Add torrent given on command line processParams(torrentCmdLine); #ifdef Q_WS_MAC //qt_mac_set_dock_menu(icon_CurTray); #endif // Make sure the Window is visible if we don't have a tray icon if (!systrayIcon && isHidden()) { show(); activateWindow(); raise(); } connect(Session::instance(), SIGNAL(serverNameResolved(QString)), this, SLOT(handleServerNameResolved(QString))); connect(Session::instance(), SIGNAL(serverConnectionInitialized(quint32,quint32,quint32)), this, SLOT(handleServerConnectionInitialized(quint32,quint32,quint32))); connect(Session::instance(), SIGNAL(serverConnectionClosed(QString)), this, SLOT(handleServerConnectionClosed(QString))); connect(Session::instance(), SIGNAL(serverStatus(int,int)), this, SLOT(handleServerStatus(int,int))); connect(Session::instance(), SIGNAL(serverMessage(QString)), this, SLOT(handleServerMessage(QString))); connect(Session::instance(), SIGNAL(serverIdentity(QString,QString)), this, SLOT(handleServerIdentity(QString,QString))); connect(Session::instance(), SIGNAL(transferAdded(QED2KHandle)), SLOT(addedTransfer(QED2KHandle))); connect(Session::instance(), SIGNAL(transferFinished(QED2KHandle)), SLOT(finishedTransfer(QED2KHandle))); //Tray actions. //connect(actionToggleVisibility, SIGNAL(triggered()), this, SLOT(toggleVisibility())); //connect(actionStart_All, SIGNAL(triggered()), Session::instance(), SLOT(resumeAllTransfers())); //connect(actionPause_All, SIGNAL(triggered()), Session::instance(), SLOT(pauseAllTransfers())); actionConnect->trigger(); Session::instance()->loadDirectory(pref.inputDir()); }