2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022-2023 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
30 #include "mainwindow.h"
32 #include <QtSystemDetection>
38 #include <QActionGroup>
40 #include <QCloseEvent>
43 #include <QDesktopServices>
44 #include <QFileDialog>
45 #include <QFileSystemWatcher>
49 #include <QMessageBox>
50 #include <QMetaObject>
53 #include <QPushButton>
60 #include "base/bittorrent/session.h"
61 #include "base/bittorrent/sessionstatus.h"
62 #include "base/global.h"
63 #include "base/net/downloadmanager.h"
64 #include "base/path.h"
65 #include "base/preferences.h"
66 #include "base/rss/rss_folder.h"
67 #include "base/rss/rss_session.h"
68 #include "base/utils/foreignapps.h"
69 #include "base/utils/fs.h"
70 #include "base/utils/misc.h"
71 #include "base/utils/password.h"
72 #include "base/version.h"
73 #include "aboutdialog.h"
74 #include "autoexpandabledialog.h"
75 #include "cookiesdialog.h"
76 #include "desktopintegration.h"
77 #include "downloadfromurldialog.h"
78 #include "executionlogwidget.h"
79 #include "hidabletabwidget.h"
80 #include "interfaces/iguiapplication.h"
82 #include "optionsdialog.h"
83 #include "powermanagement/powermanagement.h"
84 #include "properties/peerlistwidget.h"
85 #include "properties/propertieswidget.h"
86 #include "properties/proptabbar.h"
87 #include "rss/rsswidget.h"
88 #include "search/searchwidget.h"
89 #include "speedlimitdialog.h"
90 #include "statsdialog.h"
91 #include "statusbar.h"
92 #include "torrentcreatordialog.h"
93 #include "trackerlist/trackerlistwidget.h"
94 #include "transferlistfilterswidget.h"
95 #include "transferlistmodel.h"
96 #include "transferlistwidget.h"
97 #include "ui_mainwindow.h"
98 #include "uithememanager.h"
102 #include "macosdockbadge/badger.h"
104 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
105 #include "programupdater.h"
108 using namespace std::chrono_literals
;
112 #define SETTINGS_KEY(name) u"GUI/" name
113 #define EXECUTIONLOG_SETTINGS_KEY(name) (SETTINGS_KEY(u"Log/"_s) name)
115 const std::chrono::seconds PREVENT_SUSPEND_INTERVAL
{60};
117 bool isTorrentLink(const QString
&str
)
119 return str
.startsWith(u
"magnet:", Qt::CaseInsensitive
)
120 || str
.endsWith(TORRENT_FILE_EXTENSION
, Qt::CaseInsensitive
)
121 || (!str
.startsWith(u
"file:", Qt::CaseInsensitive
)
122 && Net::DownloadManager::hasSupportedScheme(str
));
126 MainWindow::MainWindow(IGUIApplication
*app
, const WindowState initialState
, const QString
&titleSuffix
)
127 : GUIApplicationComponent(app
)
128 , m_ui(new Ui::MainWindow
)
129 , m_storeExecutionLogEnabled(EXECUTIONLOG_SETTINGS_KEY(u
"Enabled"_s
))
130 , m_storeDownloadTrackerFavicon(SETTINGS_KEY(u
"DownloadTrackerFavicon"_s
))
131 , m_storeExecutionLogTypes(EXECUTIONLOG_SETTINGS_KEY(u
"Types"_s
), Log::MsgType::ALL
)
133 , m_badger(std::make_unique
<MacUtils::Badger
>())
138 setTitleSuffix(titleSuffix
);
140 Preferences
*const pref
= Preferences::instance();
141 m_uiLocked
= pref
->isUILocked();
142 m_displaySpeedInTitle
= pref
->speedInTitleBar();
145 setWindowIcon(UIThemeManager::instance()->getIcon(u
"qbittorrent"_s
));
148 #if (defined(Q_OS_UNIX))
149 m_ui
->actionOptions
->setText(tr("Preferences"));
152 addToolbarContextMenu();
154 m_ui
->actionOpen
->setIcon(UIThemeManager::instance()->getIcon(u
"list-add"_s
));
155 m_ui
->actionDownloadFromURL
->setIcon(UIThemeManager::instance()->getIcon(u
"insert-link"_s
));
156 m_ui
->actionSetGlobalSpeedLimits
->setIcon(UIThemeManager::instance()->getIcon(u
"speedometer"_s
));
157 m_ui
->actionCreateTorrent
->setIcon(UIThemeManager::instance()->getIcon(u
"torrent-creator"_s
, u
"document-edit"_s
));
158 m_ui
->actionAbout
->setIcon(UIThemeManager::instance()->getIcon(u
"help-about"_s
));
159 m_ui
->actionStatistics
->setIcon(UIThemeManager::instance()->getIcon(u
"view-statistics"_s
));
160 m_ui
->actionTopQueuePos
->setIcon(UIThemeManager::instance()->getIcon(u
"go-top"_s
));
161 m_ui
->actionIncreaseQueuePos
->setIcon(UIThemeManager::instance()->getIcon(u
"go-up"_s
));
162 m_ui
->actionDecreaseQueuePos
->setIcon(UIThemeManager::instance()->getIcon(u
"go-down"_s
));
163 m_ui
->actionBottomQueuePos
->setIcon(UIThemeManager::instance()->getIcon(u
"go-bottom"_s
));
164 m_ui
->actionDelete
->setIcon(UIThemeManager::instance()->getIcon(u
"list-remove"_s
));
165 m_ui
->actionDocumentation
->setIcon(UIThemeManager::instance()->getIcon(u
"help-contents"_s
));
166 m_ui
->actionDonateMoney
->setIcon(UIThemeManager::instance()->getIcon(u
"wallet-open"_s
));
167 m_ui
->actionExit
->setIcon(UIThemeManager::instance()->getIcon(u
"application-exit"_s
));
168 m_ui
->actionLock
->setIcon(UIThemeManager::instance()->getIcon(u
"object-locked"_s
));
169 m_ui
->actionOptions
->setIcon(UIThemeManager::instance()->getIcon(u
"configure"_s
, u
"preferences-system"_s
));
170 m_ui
->actionPause
->setIcon(UIThemeManager::instance()->getIcon(u
"torrent-stop"_s
, u
"media-playback-pause"_s
));
171 m_ui
->actionPauseAll
->setIcon(UIThemeManager::instance()->getIcon(u
"torrent-stop"_s
, u
"media-playback-pause"_s
));
172 m_ui
->actionStart
->setIcon(UIThemeManager::instance()->getIcon(u
"torrent-start"_s
, u
"media-playback-start"_s
));
173 m_ui
->actionStartAll
->setIcon(UIThemeManager::instance()->getIcon(u
"torrent-start"_s
, u
"media-playback-start"_s
));
174 m_ui
->menuAutoShutdownOnDownloadsCompletion
->setIcon(UIThemeManager::instance()->getIcon(u
"task-complete"_s
, u
"application-exit"_s
));
175 m_ui
->actionManageCookies
->setIcon(UIThemeManager::instance()->getIcon(u
"browser-cookies"_s
, u
"preferences-web-browser-cookies"_s
));
176 m_ui
->menuLog
->setIcon(UIThemeManager::instance()->getIcon(u
"help-contents"_s
));
177 m_ui
->actionCheckForUpdates
->setIcon(UIThemeManager::instance()->getIcon(u
"view-refresh"_s
));
179 auto *lockMenu
= new QMenu(m_ui
->menuView
);
180 lockMenu
->addAction(tr("&Set Password"), this, &MainWindow::defineUILockPassword
);
181 lockMenu
->addAction(tr("&Clear Password"), this, &MainWindow::clearUILockPassword
);
182 m_ui
->actionLock
->setMenu(lockMenu
);
184 // Creating Bittorrent session
185 updateAltSpeedsBtn(BitTorrent::Session::instance()->isAltGlobalSpeedLimitEnabled());
187 connect(BitTorrent::Session::instance(), &BitTorrent::Session::speedLimitModeChanged
, this, &MainWindow::updateAltSpeedsBtn
);
189 qDebug("create tabWidget");
190 m_tabs
= new HidableTabWidget(this);
191 connect(m_tabs
.data(), &QTabWidget::currentChanged
, this, &MainWindow::tabChanged
);
193 m_splitter
= new QSplitter(Qt::Horizontal
, this);
194 // vSplitter->setChildrenCollapsible(false);
196 auto *hSplitter
= new QSplitter(Qt::Vertical
, this);
197 hSplitter
->setChildrenCollapsible(false);
198 hSplitter
->setFrameShape(QFrame::NoFrame
);
201 m_columnFilterEdit
= new LineEdit
;
202 m_columnFilterEdit
->setPlaceholderText(tr("Filter torrents..."));
203 m_columnFilterEdit
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
204 m_columnFilterEdit
->setFixedWidth(200);
205 m_columnFilterEdit
->setContextMenuPolicy(Qt::CustomContextMenu
);
206 connect(m_columnFilterEdit
, &QWidget::customContextMenuRequested
, this, &MainWindow::showFilterContextMenu
);
207 auto *columnFilterLabel
= new QLabel(tr("Filter by:"));
208 m_columnFilterComboBox
= new QComboBox
;
209 QHBoxLayout
*columnFilterLayout
= new QHBoxLayout(m_columnFilterWidget
);
210 columnFilterLayout
->setContentsMargins(0, 0, 0, 0);
211 auto *columnFilterSpacer
= new QWidget(this);
212 columnFilterSpacer
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
213 columnFilterLayout
->addWidget(columnFilterSpacer
);
214 columnFilterLayout
->addWidget(m_columnFilterEdit
);
215 columnFilterLayout
->addWidget(columnFilterLabel
, 0);
216 columnFilterLayout
->addWidget(m_columnFilterComboBox
, 0);
217 m_columnFilterWidget
= new QWidget(this);
218 m_columnFilterWidget
->setLayout(columnFilterLayout
);
219 m_columnFilterAction
= m_ui
->toolBar
->insertWidget(m_ui
->actionLock
, m_columnFilterWidget
);
221 auto *spacer
= new QWidget(this);
222 spacer
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
223 m_ui
->toolBar
->insertWidget(m_columnFilterAction
, spacer
);
226 m_transferListWidget
= new TransferListWidget(hSplitter
, this);
227 m_propertiesWidget
= new PropertiesWidget(hSplitter
);
228 connect(m_transferListWidget
, &TransferListWidget::currentTorrentChanged
, m_propertiesWidget
, &PropertiesWidget::loadTorrentInfos
);
229 hSplitter
->addWidget(m_transferListWidget
);
230 hSplitter
->addWidget(m_propertiesWidget
);
231 m_splitter
->addWidget(hSplitter
);
232 m_splitter
->setCollapsible(0, false);
233 m_tabs
->addTab(m_splitter
,
235 UIThemeManager::instance()->getIcon(u
"folder-remote"_s
),
239 const QVector
<TransferListModel::Column
> filterTypes
= {TransferListModel::Column::TR_NAME
, TransferListModel::Column::TR_SAVE_PATH
};
240 for (const TransferListModel::Column type
: filterTypes
)
242 const QString typeName
= m_transferListWidget
->getSourceModel()->headerData(type
, Qt::Horizontal
, Qt::DisplayRole
).value
<QString
>();
243 m_columnFilterComboBox
->addItem(typeName
, type
);
245 connect(m_columnFilterComboBox
, &QComboBox::currentIndexChanged
, this, &MainWindow::applyTransferListFilter
);
246 connect(m_columnFilterEdit
, &LineEdit::textChanged
, this, &MainWindow::applyTransferListFilter
);
247 connect(hSplitter
, &QSplitter::splitterMoved
, this, &MainWindow::saveSettings
);
248 connect(m_splitter
, &QSplitter::splitterMoved
, this, &MainWindow::saveSplitterSettings
);
251 // Increase top spacing to avoid tab overlapping
252 m_ui
->centralWidgetLayout
->addSpacing(8);
255 m_ui
->centralWidgetLayout
->addWidget(m_tabs
);
257 m_queueSeparator
= m_ui
->toolBar
->insertSeparator(m_ui
->actionTopQueuePos
);
258 m_queueSeparatorMenu
= m_ui
->menuEdit
->insertSeparator(m_ui
->actionTopQueuePos
);
261 for (QAction
*action
: asConst(m_ui
->toolBar
->actions()))
263 if (action
->isSeparator())
265 QWidget
*spacer
= new QWidget(this);
266 spacer
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
267 spacer
->setMinimumWidth(16);
268 m_ui
->toolBar
->insertWidget(action
, spacer
);
269 m_ui
->toolBar
->removeAction(action
);
273 QWidget
*spacer
= new QWidget(this);
274 spacer
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
275 spacer
->setMinimumWidth(8);
276 m_ui
->toolBar
->insertWidget(m_ui
->actionDownloadFromURL
, spacer
);
279 QWidget
*spacer
= new QWidget(this);
280 spacer
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
281 spacer
->setMinimumWidth(8);
282 m_ui
->toolBar
->addWidget(spacer
);
286 // Transfer list slots
287 connect(m_ui
->actionStart
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::startSelectedTorrents
);
288 connect(m_ui
->actionStartAll
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::resumeAllTorrents
);
289 connect(m_ui
->actionPause
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::pauseSelectedTorrents
);
290 connect(m_ui
->actionPauseAll
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::pauseAllTorrents
);
291 connect(m_ui
->actionDelete
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::softDeleteSelectedTorrents
);
292 connect(m_ui
->actionTopQueuePos
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::topQueuePosSelectedTorrents
);
293 connect(m_ui
->actionIncreaseQueuePos
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::increaseQueuePosSelectedTorrents
);
294 connect(m_ui
->actionDecreaseQueuePos
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::decreaseQueuePosSelectedTorrents
);
295 connect(m_ui
->actionBottomQueuePos
, &QAction::triggered
, m_transferListWidget
, &TransferListWidget::bottomQueuePosSelectedTorrents
);
297 connect(m_ui
->actionToggleVisibility
, &QAction::triggered
, this, &MainWindow::toggleVisibility
);
299 connect(m_ui
->actionMinimize
, &QAction::triggered
, this, &MainWindow::minimizeWindow
);
300 connect(m_ui
->actionUseAlternativeSpeedLimits
, &QAction::triggered
, this, &MainWindow::toggleAlternativeSpeeds
);
302 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
303 connect(m_ui
->actionCheckForUpdates
, &QAction::triggered
, this, [this]() { checkProgramUpdate(true); });
305 // trigger an early check on startup
306 if (pref
->isUpdateCheckEnabled())
307 checkProgramUpdate(false);
309 m_ui
->actionCheckForUpdates
->setVisible(false);
312 // Certain menu items should reside at specific places on macOS.
313 // Qt partially does it on its own, but updates and different languages require tuning.
314 m_ui
->actionExit
->setMenuRole(QAction::QuitRole
);
315 m_ui
->actionAbout
->setMenuRole(QAction::AboutRole
);
316 m_ui
->actionCheckForUpdates
->setMenuRole(QAction::ApplicationSpecificRole
);
317 m_ui
->actionOptions
->setMenuRole(QAction::PreferencesRole
);
319 connect(m_ui
->actionManageCookies
, &QAction::triggered
, this, &MainWindow::manageCookies
);
321 // Initialise system sleep inhibition timer
322 m_pwr
= new PowerManagement(this);
323 m_preventTimer
= new QTimer(this);
324 m_preventTimer
->setSingleShot(true);
325 connect(m_preventTimer
, &QTimer::timeout
, this, &MainWindow::updatePowerManagementState
);
326 connect(pref
, &Preferences::changed
, this, &MainWindow::updatePowerManagementState
);
327 updatePowerManagementState();
329 // Configure BT session according to options
332 connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &MainWindow::reloadSessionStats
);
333 connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated
, this, &MainWindow::reloadTorrentStats
);
335 // Accept drag 'n drops
336 setAcceptDrops(true);
337 createKeyboardShortcuts();
340 setUnifiedTitleAndToolBarOnMac(true);
344 m_ui
->actionTopToolBar
->setChecked(pref
->isToolbarDisplayed());
345 m_ui
->actionShowStatusbar
->setChecked(pref
->isStatusbarDisplayed());
346 m_ui
->actionSpeedInTitleBar
->setChecked(pref
->speedInTitleBar());
347 m_ui
->actionRSSReader
->setChecked(pref
->isRSSWidgetEnabled());
348 m_ui
->actionSearchWidget
->setChecked(pref
->isSearchEnabled());
349 m_ui
->actionExecutionLogs
->setChecked(isExecutionLogEnabled());
351 const Log::MsgTypes flags
= executionLogMsgTypes();
352 m_ui
->actionNormalMessages
->setChecked(flags
.testFlag(Log::NORMAL
));
353 m_ui
->actionInformationMessages
->setChecked(flags
.testFlag(Log::INFO
));
354 m_ui
->actionWarningMessages
->setChecked(flags
.testFlag(Log::WARNING
));
355 m_ui
->actionCriticalMessages
->setChecked(flags
.testFlag(Log::CRITICAL
));
357 displayRSSTab(m_ui
->actionRSSReader
->isChecked());
358 on_actionExecutionLogs_triggered(m_ui
->actionExecutionLogs
->isChecked());
359 on_actionNormalMessages_triggered(m_ui
->actionNormalMessages
->isChecked());
360 on_actionInformationMessages_triggered(m_ui
->actionInformationMessages
->isChecked());
361 on_actionWarningMessages_triggered(m_ui
->actionWarningMessages
->isChecked());
362 on_actionCriticalMessages_triggered(m_ui
->actionCriticalMessages
->isChecked());
363 if (m_ui
->actionSearchWidget
->isChecked())
364 QMetaObject::invokeMethod(this, &MainWindow::on_actionSearchWidget_triggered
, Qt::QueuedConnection
);
365 // Auto shutdown actions
366 auto *autoShutdownGroup
= new QActionGroup(this);
367 autoShutdownGroup
->setExclusive(true);
368 autoShutdownGroup
->addAction(m_ui
->actionAutoShutdownDisabled
);
369 autoShutdownGroup
->addAction(m_ui
->actionAutoExit
);
370 autoShutdownGroup
->addAction(m_ui
->actionAutoShutdown
);
371 autoShutdownGroup
->addAction(m_ui
->actionAutoSuspend
);
372 autoShutdownGroup
->addAction(m_ui
->actionAutoHibernate
);
373 #if (!defined(Q_OS_UNIX) || defined(Q_OS_MACOS)) || defined(QBT_USES_DBUS)
374 m_ui
->actionAutoShutdown
->setChecked(pref
->shutdownWhenDownloadsComplete());
375 m_ui
->actionAutoSuspend
->setChecked(pref
->suspendWhenDownloadsComplete());
376 m_ui
->actionAutoHibernate
->setChecked(pref
->hibernateWhenDownloadsComplete());
378 m_ui
->actionAutoShutdown
->setDisabled(true);
379 m_ui
->actionAutoSuspend
->setDisabled(true);
380 m_ui
->actionAutoHibernate
->setDisabled(true);
382 m_ui
->actionAutoExit
->setChecked(pref
->shutdownqBTWhenDownloadsComplete());
384 if (!autoShutdownGroup
->checkedAction())
385 m_ui
->actionAutoShutdownDisabled
->setChecked(true);
387 // Load Window state and sizes
390 app
->desktopIntegration()->setMenu(createDesktopIntegrationMenu());
392 m_ui
->actionLock
->setVisible(app
->desktopIntegration()->isActive());
393 connect(app
->desktopIntegration(), &DesktopIntegration::stateChanged
, this, [this, app
]()
395 m_ui
->actionLock
->setVisible(app
->desktopIntegration()->isActive());
398 connect(app
->desktopIntegration(), &DesktopIntegration::notificationClicked
, this, &MainWindow::desktopNotificationClicked
);
399 connect(app
->desktopIntegration(), &DesktopIntegration::activationRequested
, this, [this]()
410 if (initialState
== WindowState::Normal
)
418 // Make sure the Window is visible if we don't have a tray icon
422 if (app
->desktopIntegration()->isActive())
424 if ((initialState
== WindowState::Normal
) && !m_uiLocked
)
430 else if (initialState
== WindowState::Minimized
)
433 if (pref
->minimizeToTray())
436 if (!pref
->minimizeToTrayNotified())
438 app
->desktopIntegration()->showNotification(tr("qBittorrent is minimized to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));
439 pref
->setMinimizeToTrayNotified(true);
446 // Make sure the Window is visible if we don't have a tray icon
447 if (initialState
!= WindowState::Normal
)
460 const bool isFiltersSidebarVisible
= pref
->isFiltersSidebarVisible();
461 m_ui
->actionShowFiltersSidebar
->setChecked(isFiltersSidebarVisible
);
462 if (isFiltersSidebarVisible
)
464 showFiltersSidebar(true);
468 m_transferListWidget
->applyStatusFilter(pref
->getTransSelFilter());
469 m_transferListWidget
->applyCategoryFilter(QString());
470 m_transferListWidget
->applyTagFilter(std::nullopt
);
471 m_transferListWidget
->applyTrackerFilterAll();
474 // Start watching the executable for updates
475 m_executableWatcher
= new QFileSystemWatcher(this);
476 connect(m_executableWatcher
, &QFileSystemWatcher::fileChanged
, this, &MainWindow::notifyOfUpdate
);
477 m_executableWatcher
->addPath(qApp
->applicationFilePath());
479 m_transferListWidget
->setFocus();
481 // Update the number of torrents (tab)
483 connect(m_transferListWidget
->getSourceModel(), &QAbstractItemModel::rowsInserted
, this, &MainWindow::updateNbTorrents
);
484 connect(m_transferListWidget
->getSourceModel(), &QAbstractItemModel::rowsRemoved
, this, &MainWindow::updateNbTorrents
);
486 connect(pref
, &Preferences::changed
, this, &MainWindow::optionsSaved
);
491 MainWindow::~MainWindow()
496 bool MainWindow::isExecutionLogEnabled() const
498 return m_storeExecutionLogEnabled
;
501 void MainWindow::setExecutionLogEnabled(const bool value
)
503 m_storeExecutionLogEnabled
= value
;
506 Log::MsgTypes
MainWindow::executionLogMsgTypes() const
508 return m_storeExecutionLogTypes
;
511 void MainWindow::setExecutionLogMsgTypes(const Log::MsgTypes value
)
513 m_executionLog
->setMessageTypes(value
);
514 m_storeExecutionLogTypes
= value
;
517 bool MainWindow::isDownloadTrackerFavicon() const
519 return m_storeDownloadTrackerFavicon
;
522 void MainWindow::setDownloadTrackerFavicon(const bool value
)
524 if (m_transferListFiltersWidget
)
525 m_transferListFiltersWidget
->setDownloadTrackerFavicon(value
);
526 m_storeDownloadTrackerFavicon
= value
;
529 void MainWindow::setTitleSuffix(const QString
&suffix
)
531 const auto emDash
= QChar(0x2014);
532 const QString separator
= u
' ' + emDash
+ u
' ';
533 m_windowTitle
= QStringLiteral("qBittorrent " QBT_VERSION
)
534 + (!suffix
.isEmpty() ? (separator
+ suffix
) : QString());
536 setWindowTitle(m_windowTitle
);
539 void MainWindow::addToolbarContextMenu()
541 const Preferences
*const pref
= Preferences::instance();
542 m_toolbarMenu
= new QMenu(this);
544 m_ui
->toolBar
->setContextMenuPolicy(Qt::CustomContextMenu
);
545 connect(m_ui
->toolBar
, &QWidget::customContextMenuRequested
, this, &MainWindow::toolbarMenuRequested
);
547 QAction
*iconsOnly
= m_toolbarMenu
->addAction(tr("Icons Only"), this, &MainWindow::toolbarIconsOnly
);
548 QAction
*textOnly
= m_toolbarMenu
->addAction(tr("Text Only"), this, &MainWindow::toolbarTextOnly
);
549 QAction
*textBesideIcons
= m_toolbarMenu
->addAction(tr("Text Alongside Icons"), this, &MainWindow::toolbarTextBeside
);
550 QAction
*textUnderIcons
= m_toolbarMenu
->addAction(tr("Text Under Icons"), this, &MainWindow::toolbarTextUnder
);
551 QAction
*followSystemStyle
= m_toolbarMenu
->addAction(tr("Follow System Style"), this, &MainWindow::toolbarFollowSystem
);
553 auto *textPositionGroup
= new QActionGroup(m_toolbarMenu
);
554 textPositionGroup
->addAction(iconsOnly
);
555 iconsOnly
->setCheckable(true);
556 textPositionGroup
->addAction(textOnly
);
557 textOnly
->setCheckable(true);
558 textPositionGroup
->addAction(textBesideIcons
);
559 textBesideIcons
->setCheckable(true);
560 textPositionGroup
->addAction(textUnderIcons
);
561 textUnderIcons
->setCheckable(true);
562 textPositionGroup
->addAction(followSystemStyle
);
563 followSystemStyle
->setCheckable(true);
565 const auto buttonStyle
= static_cast<Qt::ToolButtonStyle
>(pref
->getToolbarTextPosition());
566 if ((buttonStyle
>= Qt::ToolButtonIconOnly
) && (buttonStyle
<= Qt::ToolButtonFollowStyle
))
567 m_ui
->toolBar
->setToolButtonStyle(buttonStyle
);
570 case Qt::ToolButtonIconOnly
:
571 iconsOnly
->setChecked(true);
573 case Qt::ToolButtonTextOnly
:
574 textOnly
->setChecked(true);
576 case Qt::ToolButtonTextBesideIcon
:
577 textBesideIcons
->setChecked(true);
579 case Qt::ToolButtonTextUnderIcon
:
580 textUnderIcons
->setChecked(true);
583 followSystemStyle
->setChecked(true);
587 void MainWindow::manageCookies()
589 auto *cookieDialog
= new CookiesDialog(this);
590 cookieDialog
->setAttribute(Qt::WA_DeleteOnClose
);
591 cookieDialog
->open();
594 void MainWindow::toolbarMenuRequested()
596 m_toolbarMenu
->popup(QCursor::pos());
599 void MainWindow::toolbarIconsOnly()
601 m_ui
->toolBar
->setToolButtonStyle(Qt::ToolButtonIconOnly
);
602 Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonIconOnly
);
605 void MainWindow::toolbarTextOnly()
607 m_ui
->toolBar
->setToolButtonStyle(Qt::ToolButtonTextOnly
);
608 Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonTextOnly
);
611 void MainWindow::toolbarTextBeside()
613 m_ui
->toolBar
->setToolButtonStyle(Qt::ToolButtonTextBesideIcon
);
614 Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonTextBesideIcon
);
617 void MainWindow::toolbarTextUnder()
619 m_ui
->toolBar
->setToolButtonStyle(Qt::ToolButtonTextUnderIcon
);
620 Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonTextUnderIcon
);
623 void MainWindow::toolbarFollowSystem()
625 m_ui
->toolBar
->setToolButtonStyle(Qt::ToolButtonFollowStyle
);
626 Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonFollowStyle
);
629 bool MainWindow::defineUILockPassword()
632 const QString newPassword
= AutoExpandableDialog::getText(this, tr("UI lock password")
633 , tr("Please type the UI lock password:"), QLineEdit::Password
, {}, &ok
);
637 if (newPassword
.size() < 3)
639 QMessageBox::warning(this, tr("Invalid password"), tr("The password must be at least 3 characters long"));
643 Preferences::instance()->setUILockPassword(Utils::Password::PBKDF2::generate(newPassword
));
647 void MainWindow::clearUILockPassword()
649 const QMessageBox::StandardButton answer
= QMessageBox::question(this, tr("Clear the password")
650 , tr("Are you sure you want to clear the password?"), (QMessageBox::Yes
| QMessageBox::No
), QMessageBox::No
);
651 if (answer
== QMessageBox::Yes
)
652 Preferences::instance()->setUILockPassword({});
655 void MainWindow::on_actionLock_triggered()
657 Preferences
*const pref
= Preferences::instance();
659 // Check if there is a password
660 if (pref
->getUILockPassword().isEmpty())
662 if (!defineUILockPassword())
666 // Lock the interface
668 pref
->setUILocked(true);
669 app()->desktopIntegration()->menu()->setEnabled(false);
673 void MainWindow::handleRSSUnreadCountUpdated(int count
)
675 m_tabs
->setTabText(m_tabs
->indexOf(m_rssWidget
), tr("RSS (%1)").arg(count
));
678 void MainWindow::displayRSSTab(bool enable
)
685 m_rssWidget
= new RSSWidget(app(), m_tabs
);
686 connect(m_rssWidget
.data(), &RSSWidget::unreadCountUpdated
, this, &MainWindow::handleRSSUnreadCountUpdated
);
688 m_tabs
->addTab(m_rssWidget
, tr("RSS (%1)").arg(RSS::Session::instance()->rootFolder()->unreadCount()));
690 const int indexTab
= m_tabs
->addTab(m_rssWidget
, tr("RSS (%1)").arg(RSS::Session::instance()->rootFolder()->unreadCount()));
691 m_tabs
->setTabIcon(indexTab
, UIThemeManager::instance()->getIcon(u
"application-rss"_s
));
701 void MainWindow::showFilterContextMenu()
703 const Preferences
*pref
= Preferences::instance();
705 QMenu
*menu
= m_columnFilterEdit
->createStandardContextMenu();
706 menu
->setAttribute(Qt::WA_DeleteOnClose
);
707 menu
->addSeparator();
709 QAction
*useRegexAct
= menu
->addAction(tr("Use regular expressions"));
710 useRegexAct
->setCheckable(true);
711 useRegexAct
->setChecked(pref
->getRegexAsFilteringPatternForTransferList());
712 connect(useRegexAct
, &QAction::toggled
, pref
, &Preferences::setRegexAsFilteringPatternForTransferList
);
713 connect(useRegexAct
, &QAction::toggled
, this, &MainWindow::applyTransferListFilter
);
715 menu
->popup(QCursor::pos());
718 void MainWindow::displaySearchTab(bool enable
)
720 Preferences::instance()->setSearchEnabled(enable
);
726 m_searchWidget
= new SearchWidget(app(), this);
727 m_tabs
->insertTab(1, m_searchWidget
,
729 UIThemeManager::instance()->getIcon(u
"edit-find"_s
),
736 delete m_searchWidget
;
740 void MainWindow::toggleFocusBetweenLineEdits()
742 if (m_columnFilterEdit
->hasFocus() && (m_propertiesWidget
->tabBar()->currentIndex() == PropTabBar::FilesTab
))
744 m_propertiesWidget
->contentFilterLine()->setFocus();
745 m_propertiesWidget
->contentFilterLine()->selectAll();
749 m_columnFilterEdit
->setFocus();
750 m_columnFilterEdit
->selectAll();
754 void MainWindow::updateNbTorrents()
756 m_tabs
->setTabText(0, tr("Transfers (%1)").arg(m_transferListWidget
->getSourceModel()->rowCount()));
759 void MainWindow::on_actionDocumentation_triggered() const
761 QDesktopServices::openUrl(QUrl(u
"https://doc.qbittorrent.org"_s
));
764 void MainWindow::tabChanged([[maybe_unused
]] const int newTab
)
766 // We cannot rely on the index newTab
767 // because the tab order is undetermined now
768 if (m_tabs
->currentWidget() == m_splitter
)
770 qDebug("Changed tab to transfer list, refreshing the list");
771 m_propertiesWidget
->loadDynamicData();
772 m_columnFilterAction
->setVisible(true);
775 m_columnFilterAction
->setVisible(false);
777 if (m_tabs
->currentWidget() == m_searchWidget
)
779 qDebug("Changed tab to search engine, giving focus to search input");
780 m_searchWidget
->giveFocusToSearchInput();
784 void MainWindow::saveSettings() const
786 auto *pref
= Preferences::instance();
787 pref
->setMainGeometry(saveGeometry());
788 m_propertiesWidget
->saveSettings();
791 void MainWindow::saveSplitterSettings() const
793 if (!m_transferListFiltersWidget
)
796 auto *pref
= Preferences::instance();
797 pref
->setFiltersSidebarWidth(m_splitter
->sizes()[0]);
800 void MainWindow::cleanup()
803 saveSplitterSettings();
805 // delete RSSWidget explicitly to avoid crash in
806 // handleRSSUnreadCountUpdated() at application shutdown
809 delete m_executableWatcher
;
811 m_preventTimer
->stop();
813 #if (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
814 if (m_programUpdateTimer
)
815 m_programUpdateTimer
->stop();
818 // remove all child widgets
819 while (auto *w
= findChild
<QWidget
*>())
823 void MainWindow::loadSettings()
825 const auto *pref
= Preferences::instance();
827 if (const QByteArray mainGeo
= pref
->getMainGeometry();
828 !mainGeo
.isEmpty() && restoreGeometry(mainGeo
))
830 m_posInitialized
= true;
834 void MainWindow::desktopNotificationClicked()
840 // Ask for UI lock password
853 void MainWindow::createKeyboardShortcuts()
855 m_ui
->actionCreateTorrent
->setShortcut(QKeySequence::New
);
856 m_ui
->actionOpen
->setShortcut(QKeySequence::Open
);
857 m_ui
->actionDelete
->setShortcut(QKeySequence::Delete
);
858 m_ui
->actionDelete
->setShortcutContext(Qt::WidgetShortcut
); // nullify its effect: delete key event is handled by respective widgets, not here
859 m_ui
->actionDownloadFromURL
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_O
);
860 m_ui
->actionExit
->setShortcut(Qt::CTRL
| Qt::Key_Q
);
862 m_ui
->actionCloseWindow
->setShortcut(QKeySequence::Close
);
864 m_ui
->actionCloseWindow
->setVisible(false);
867 const auto *switchTransferShortcut
= new QShortcut((Qt::ALT
| Qt::Key_1
), this);
868 connect(switchTransferShortcut
, &QShortcut::activated
, this, &MainWindow::displayTransferTab
);
869 const auto *switchSearchShortcut
= new QShortcut((Qt::ALT
| Qt::Key_2
), this);
870 connect(switchSearchShortcut
, &QShortcut::activated
, this, qOverload
<>(&MainWindow::displaySearchTab
));
871 const auto *switchRSSShortcut
= new QShortcut((Qt::ALT
| Qt::Key_3
), this);
872 connect(switchRSSShortcut
, &QShortcut::activated
, this, qOverload
<>(&MainWindow::displayRSSTab
));
873 const auto *switchExecutionLogShortcut
= new QShortcut((Qt::ALT
| Qt::Key_4
), this);
874 connect(switchExecutionLogShortcut
, &QShortcut::activated
, this, &MainWindow::displayExecutionLogTab
);
875 const auto *switchSearchFilterShortcut
= new QShortcut(QKeySequence::Find
, m_transferListWidget
);
876 connect(switchSearchFilterShortcut
, &QShortcut::activated
, this, &MainWindow::toggleFocusBetweenLineEdits
);
877 const auto *switchSearchFilterShortcutAlternative
= new QShortcut((Qt::CTRL
| Qt::Key_E
), m_transferListWidget
);
878 connect(switchSearchFilterShortcutAlternative
, &QShortcut::activated
, this, &MainWindow::toggleFocusBetweenLineEdits
);
880 m_ui
->actionDocumentation
->setShortcut(QKeySequence::HelpContents
);
881 m_ui
->actionOptions
->setShortcut(Qt::ALT
| Qt::Key_O
);
882 m_ui
->actionStatistics
->setShortcut(Qt::CTRL
| Qt::Key_I
);
883 m_ui
->actionStart
->setShortcut(Qt::CTRL
| Qt::Key_S
);
884 m_ui
->actionStartAll
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_S
);
885 m_ui
->actionPause
->setShortcut(Qt::CTRL
| Qt::Key_P
);
886 m_ui
->actionPauseAll
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_P
);
887 m_ui
->actionBottomQueuePos
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Minus
);
888 m_ui
->actionDecreaseQueuePos
->setShortcut(Qt::CTRL
| Qt::Key_Minus
);
889 m_ui
->actionIncreaseQueuePos
->setShortcut(Qt::CTRL
| Qt::Key_Plus
);
890 m_ui
->actionTopQueuePos
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Plus
);
892 m_ui
->actionMinimize
->setShortcut(Qt::CTRL
| Qt::Key_M
);
893 addAction(m_ui
->actionMinimize
);
897 // Keyboard shortcuts slots
898 void MainWindow::displayTransferTab() const
900 m_tabs
->setCurrentWidget(m_splitter
);
903 void MainWindow::displaySearchTab()
907 m_ui
->actionSearchWidget
->setChecked(true);
908 displaySearchTab(true);
911 m_tabs
->setCurrentWidget(m_searchWidget
);
914 void MainWindow::displayRSSTab()
918 m_ui
->actionRSSReader
->setChecked(true);
922 m_tabs
->setCurrentWidget(m_rssWidget
);
925 void MainWindow::displayExecutionLogTab()
929 m_ui
->actionExecutionLogs
->setChecked(true);
930 on_actionExecutionLogs_triggered(true);
933 m_tabs
->setCurrentWidget(m_executionLog
);
936 // End of keyboard shortcuts slots
938 void MainWindow::on_actionSetGlobalSpeedLimits_triggered()
940 auto *dialog
= new SpeedLimitDialog
{this};
941 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
945 // Necessary if we want to close the window
946 // in one time if "close to systray" is enabled
947 void MainWindow::on_actionExit_triggered()
949 // UI locking enforcement.
950 if (isHidden() && m_uiLocked
)
951 // Ask for UI lock password
952 if (!unlockUI()) return;
959 void MainWindow::on_actionCloseWindow_triggered()
961 // On macOS window close is basically equivalent to window hide.
962 // If you decide to implement this functionality for other OS,
963 // then you will also need ui lock checks like in actionExit.
968 QWidget
*MainWindow::currentTabWidget() const
970 if (isMinimized() || !isVisible())
972 if (m_tabs
->currentIndex() == 0)
973 return m_transferListWidget
;
974 return m_tabs
->currentWidget();
977 TransferListWidget
*MainWindow::transferListWidget() const
979 return m_transferListWidget
;
982 bool MainWindow::unlockUI()
984 if (m_unlockDlgShowing
)
988 const QString password
= AutoExpandableDialog::getText(this, tr("UI lock password")
989 , tr("Please type the UI lock password:"), QLineEdit::Password
, {}, &ok
);
990 if (!ok
) return false;
992 Preferences
*const pref
= Preferences::instance();
994 const QByteArray secret
= pref
->getUILockPassword();
995 if (!Utils::Password::PBKDF2::verify(secret
, password
))
997 QMessageBox::warning(this, tr("Invalid password"), tr("The password is invalid"));
1002 pref
->setUILocked(false);
1003 app()->desktopIntegration()->menu()->setEnabled(true);
1007 void MainWindow::notifyOfUpdate(const QString
&)
1009 // Show restart message
1010 m_statusBar
->showRestartRequired();
1011 LogMsg(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective.")
1013 // Delete the executable watcher
1014 delete m_executableWatcher
;
1015 m_executableWatcher
= nullptr;
1019 // Toggle Main window visibility
1020 void MainWindow::toggleVisibility()
1024 if (m_uiLocked
&& !unlockUI()) // Ask for UI lock password
1027 // Make sure the window is not minimized
1028 setWindowState((windowState() & ~Qt::WindowMinimized
) | Qt::WindowActive
);
1040 #endif // Q_OS_MACOS
1042 // Display About Dialog
1043 void MainWindow::on_actionAbout_triggered()
1048 m_aboutDlg
->activateWindow();
1052 m_aboutDlg
= new AboutDialog(this);
1053 m_aboutDlg
->setAttribute(Qt::WA_DeleteOnClose
);
1058 void MainWindow::on_actionStatistics_triggered()
1062 m_statsDlg
->activateWindow();
1066 m_statsDlg
= new StatsDialog(this);
1067 m_statsDlg
->setAttribute(Qt::WA_DeleteOnClose
);
1072 void MainWindow::showEvent(QShowEvent
*e
)
1074 qDebug("** Show Event **");
1079 // preparations before showing the window
1083 m_propertiesWidget
->readSettings();
1084 m_neverShown
= false;
1087 if (currentTabWidget() == m_transferListWidget
)
1088 m_propertiesWidget
->loadDynamicData();
1090 // Make sure the window is initially centered
1091 if (!m_posInitialized
)
1093 move(Utils::Gui::screenCenter(this));
1094 m_posInitialized
= true;
1099 // to avoid blank screen when restoring from tray icon
1104 void MainWindow::keyPressEvent(QKeyEvent
*event
)
1106 if (event
->matches(QKeySequence::Paste
))
1108 const QMimeData
*mimeData
= QGuiApplication::clipboard()->mimeData();
1110 if (mimeData
->hasText())
1112 const QStringList lines
= mimeData
->text().split(u
'\n', Qt::SkipEmptyParts
);
1114 for (QString line
: lines
)
1116 line
= line
.trimmed();
1118 if (!isTorrentLink(line
))
1121 app()->addTorrentManager()->addTorrent(line
);
1128 QMainWindow::keyPressEvent(event
);
1131 // Called when we close the program
1132 void MainWindow::closeEvent(QCloseEvent
*e
)
1134 Preferences
*const pref
= Preferences::instance();
1143 const bool goToSystrayOnExit
= pref
->closeToTray();
1144 if (!m_forceExit
&& app()->desktopIntegration()->isActive() && goToSystrayOnExit
&& !this->isHidden())
1147 QMetaObject::invokeMethod(this, &QWidget::hide
, Qt::QueuedConnection
);
1148 if (!pref
->closeToTrayNotified())
1150 app()->desktopIntegration()->showNotification(tr("qBittorrent is closed to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));
1151 pref
->setCloseToTrayNotified(true);
1155 #endif // Q_OS_MACOS
1157 const QVector
<BitTorrent::Torrent
*> allTorrents
= BitTorrent::Session::instance()->torrents();
1158 const bool hasActiveTorrents
= std::any_of(allTorrents
.cbegin(), allTorrents
.cend(), [](BitTorrent::Torrent
*torrent
)
1160 return torrent
->isActive();
1162 if (pref
->confirmOnExit() && hasActiveTorrents
)
1164 if (e
->spontaneous() || m_forceExit
)
1168 QMessageBox
confirmBox(QMessageBox::Question
, tr("Exiting qBittorrent"),
1169 // Split it because the last sentence is used in the WebUI
1170 tr("Some files are currently transferring.") + u
'\n' + tr("Are you sure you want to quit qBittorrent?"),
1171 QMessageBox::NoButton
, this);
1172 QPushButton
*noBtn
= confirmBox
.addButton(tr("&No"), QMessageBox::NoRole
);
1173 confirmBox
.addButton(tr("&Yes"), QMessageBox::YesRole
);
1174 QPushButton
*alwaysBtn
= confirmBox
.addButton(tr("&Always Yes"), QMessageBox::YesRole
);
1175 confirmBox
.setDefaultButton(noBtn
);
1177 if (!confirmBox
.clickedButton() || (confirmBox
.clickedButton() == noBtn
))
1181 m_forceExit
= false;
1184 if (confirmBox
.clickedButton() == alwaysBtn
)
1186 Preferences::instance()->setConfirmOnExit(false);
1195 // Display window to create a torrent
1196 void MainWindow::on_actionCreateTorrent_triggered()
1198 createTorrentTriggered({});
1201 void MainWindow::createTorrentTriggered(const Path
&path
)
1203 if (m_createTorrentDlg
)
1205 m_createTorrentDlg
->updateInputPath(path
);
1206 m_createTorrentDlg
->activateWindow();
1210 m_createTorrentDlg
= new TorrentCreatorDialog(this, path
);
1211 m_createTorrentDlg
->setAttribute(Qt::WA_DeleteOnClose
);
1212 m_createTorrentDlg
->show();
1216 bool MainWindow::event(QEvent
*e
)
1221 case QEvent::WindowStateChange
:
1222 qDebug("Window change event");
1223 // Now check to see if the window is minimised
1226 qDebug("minimisation");
1227 Preferences
*const pref
= Preferences::instance();
1228 if (app()->desktopIntegration()->isActive() && pref
->minimizeToTray())
1230 qDebug() << "Has active window:" << (qApp
->activeWindow() != nullptr);
1231 // Check if there is a modal window
1232 const QWidgetList allWidgets
= QApplication::allWidgets();
1233 const bool hasModalWindow
= std::any_of(allWidgets
.cbegin(), allWidgets
.cend()
1234 , [](const QWidget
*widget
) { return widget
->isModal(); });
1235 // Iconify if there is no modal window
1236 if (!hasModalWindow
)
1238 qDebug("Minimize to Tray enabled, hiding!");
1240 QMetaObject::invokeMethod(this, &QWidget::hide
, Qt::QueuedConnection
);
1241 if (!pref
->minimizeToTrayNotified())
1243 app()->desktopIntegration()->showNotification(tr("qBittorrent is minimized to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));
1244 pref
->setMinimizeToTrayNotified(true);
1251 case QEvent::ToolBarChange
:
1253 qDebug("MAC: Received a toolbar change event!");
1254 const bool ret
= QMainWindow::event(e
);
1256 qDebug("MAC: new toolbar visibility is %d", !m_ui
->actionTopToolBar
->isChecked());
1257 m_ui
->actionTopToolBar
->toggle();
1258 Preferences::instance()->setToolbarDisplayed(m_ui
->actionTopToolBar
->isChecked());
1264 #endif // Q_OS_MACOS
1266 return QMainWindow::event(e
);
1269 // action executed when a file is dropped
1270 void MainWindow::dropEvent(QDropEvent
*event
)
1272 event
->acceptProposedAction();
1276 if (event
->mimeData()->hasUrls())
1278 for (const QUrl
&url
: asConst(event
->mimeData()->urls()))
1283 files
<< ((url
.scheme().compare(u
"file", Qt::CaseInsensitive
) == 0)
1290 files
= event
->mimeData()->text().split(u
'\n');
1293 // differentiate ".torrent" files/links & magnet links from others
1294 QStringList torrentFiles
, otherFiles
;
1295 for (const QString
&file
: asConst(files
))
1297 if (isTorrentLink(file
))
1298 torrentFiles
<< file
;
1303 // Download torrents
1304 for (const QString
&file
: asConst(torrentFiles
))
1305 app()->addTorrentManager()->addTorrent(file
);
1306 if (!torrentFiles
.isEmpty()) return;
1309 for (const QString
&file
: asConst(otherFiles
))
1311 createTorrentTriggered(Path(file
));
1313 // currently only handle the first entry
1314 // this is a stub that can be expanded later to create many torrents at once
1319 // Decode if we accept drag 'n drop or not
1320 void MainWindow::dragEnterEvent(QDragEnterEvent
*event
)
1322 for (const QString
&mime
: asConst(event
->mimeData()->formats()))
1323 qDebug("mimeData: %s", mime
.toLocal8Bit().data());
1325 if (event
->mimeData()->hasFormat(u
"text/plain"_s
) || event
->mimeData()->hasFormat(u
"text/uri-list"_s
))
1326 event
->acceptProposedAction();
1329 /*****************************************************
1333 *****************************************************/
1335 // Display a dialog to allow user to add
1336 // torrents to download list
1337 void MainWindow::on_actionOpen_triggered()
1339 Preferences
*const pref
= Preferences::instance();
1340 // Open File Open Dialog
1341 // Note: it is possible to select more than one file
1342 const QStringList pathsList
= QFileDialog::getOpenFileNames(this, tr("Open Torrent Files")
1343 , pref
->getMainLastDir().data(), tr("Torrent Files") + u
" (*" + TORRENT_FILE_EXTENSION
+ u
')');
1345 if (pathsList
.isEmpty())
1348 for (const QString
&file
: pathsList
)
1349 app()->addTorrentManager()->addTorrent(file
);
1351 // Save last dir to remember it
1352 const Path topDir
{pathsList
.at(0)};
1353 const Path parentDir
= topDir
.parentPath();
1354 pref
->setMainLastDir(parentDir
.isEmpty() ? topDir
: parentDir
);
1357 void MainWindow::activate()
1359 if (!m_uiLocked
|| unlockUI())
1367 void MainWindow::optionsSaved()
1369 LogMsg(tr("Options saved."));
1373 void MainWindow::showStatusBar(bool show
)
1377 // Remove status bar
1378 setStatusBar(nullptr);
1380 else if (!m_statusBar
)
1382 // Create status bar
1383 m_statusBar
= new StatusBar
;
1384 connect(m_statusBar
.data(), &StatusBar::connectionButtonClicked
, this, &MainWindow::showConnectionSettings
);
1385 connect(m_statusBar
.data(), &StatusBar::alternativeSpeedsButtonClicked
, this, &MainWindow::toggleAlternativeSpeeds
);
1386 setStatusBar(m_statusBar
);
1390 void MainWindow::showFiltersSidebar(const bool show
)
1392 if (show
&& !m_transferListFiltersWidget
)
1394 m_transferListFiltersWidget
= new TransferListFiltersWidget(m_splitter
, m_transferListWidget
, isDownloadTrackerFavicon());
1395 connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackersAdded
, m_transferListFiltersWidget
, &TransferListFiltersWidget::addTrackers
);
1396 connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackersRemoved
, m_transferListFiltersWidget
, &TransferListFiltersWidget::removeTrackers
);
1397 connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackersChanged
, m_transferListFiltersWidget
, &TransferListFiltersWidget::refreshTrackers
);
1398 connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerEntriesUpdated
, m_transferListFiltersWidget
, &TransferListFiltersWidget::trackerEntriesUpdated
);
1400 m_splitter
->insertWidget(0, m_transferListFiltersWidget
);
1401 m_splitter
->setCollapsible(0, true);
1402 // From https://doc.qt.io/qt-5/qsplitter.html#setSizes:
1403 // Instead, any additional/missing space is distributed amongst the widgets
1404 // according to the relative weight of the sizes.
1405 m_splitter
->setStretchFactor(0, 0);
1406 m_splitter
->setStretchFactor(1, 1);
1407 m_splitter
->setSizes({Preferences::instance()->getFiltersSidebarWidth()});
1409 else if (!show
&& m_transferListFiltersWidget
)
1411 saveSplitterSettings();
1412 delete m_transferListFiltersWidget
;
1413 m_transferListFiltersWidget
= nullptr;
1417 void MainWindow::loadPreferences()
1419 const Preferences
*pref
= Preferences::instance();
1422 if (pref
->isToolbarDisplayed())
1424 m_ui
->toolBar
->setVisible(true);
1428 // Clear search filter before hiding the top toolbar
1429 m_columnFilterEdit
->clear();
1430 m_ui
->toolBar
->setVisible(false);
1433 showStatusBar(pref
->isStatusbarDisplayed());
1435 m_transferListWidget
->setAlternatingRowColors(pref
->useAlternatingRowColors());
1436 m_propertiesWidget
->getFilesList()->setAlternatingRowColors(pref
->useAlternatingRowColors());
1437 m_propertiesWidget
->getTrackerList()->setAlternatingRowColors(pref
->useAlternatingRowColors());
1438 m_propertiesWidget
->getPeerList()->setAlternatingRowColors(pref
->useAlternatingRowColors());
1441 if (BitTorrent::Session::instance()->isQueueingSystemEnabled())
1443 if (!m_ui
->actionDecreaseQueuePos
->isVisible())
1445 m_transferListWidget
->hideQueuePosColumn(false);
1446 m_ui
->actionDecreaseQueuePos
->setVisible(true);
1447 m_ui
->actionIncreaseQueuePos
->setVisible(true);
1448 m_ui
->actionTopQueuePos
->setVisible(true);
1449 m_ui
->actionBottomQueuePos
->setVisible(true);
1451 m_queueSeparator
->setVisible(true);
1453 m_queueSeparatorMenu
->setVisible(true);
1458 if (m_ui
->actionDecreaseQueuePos
->isVisible())
1460 m_transferListWidget
->hideQueuePosColumn(true);
1461 m_ui
->actionDecreaseQueuePos
->setVisible(false);
1462 m_ui
->actionIncreaseQueuePos
->setVisible(false);
1463 m_ui
->actionTopQueuePos
->setVisible(false);
1464 m_ui
->actionBottomQueuePos
->setVisible(false);
1466 m_queueSeparator
->setVisible(false);
1468 m_queueSeparatorMenu
->setVisible(false);
1472 // Torrent properties
1473 m_propertiesWidget
->reloadPreferences();
1475 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
1476 if (pref
->isUpdateCheckEnabled())
1478 if (!m_programUpdateTimer
)
1480 m_programUpdateTimer
= new QTimer(this);
1481 m_programUpdateTimer
->setInterval(24h
);
1482 m_programUpdateTimer
->setSingleShot(true);
1483 connect(m_programUpdateTimer
, &QTimer::timeout
, this, [this]() { checkProgramUpdate(false); });
1484 m_programUpdateTimer
->start();
1489 delete m_programUpdateTimer
;
1490 m_programUpdateTimer
= nullptr;
1494 qDebug("GUI settings loaded");
1497 void MainWindow::reloadSessionStats()
1499 const BitTorrent::SessionStatus
&status
= BitTorrent::Session::instance()->status();
1500 const QString downloadRate
= Utils::Misc::friendlyUnit(status
.payloadDownloadRate
, true);
1501 const QString uploadRate
= Utils::Misc::friendlyUnit(status
.payloadUploadRate
, true);
1503 // update global information
1505 m_badger
->updateSpeed(status
.payloadDownloadRate
, status
.payloadUploadRate
);
1507 const auto toolTip
= u
"%1\n%2"_s
.arg(
1508 tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(downloadRate
)
1509 , tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(uploadRate
));
1510 app()->desktopIntegration()->setToolTip(toolTip
); // tray icon
1511 #endif // Q_OS_MACOS
1513 if (m_displaySpeedInTitle
)
1515 const QString title
= tr("[D: %1, U: %2] %3", "D = Download; U = Upload; %3 is the rest of the window title")
1516 .arg(downloadRate
, uploadRate
, m_windowTitle
);
1517 setWindowTitle(title
);
1521 void MainWindow::reloadTorrentStats(const QVector
<BitTorrent::Torrent
*> &torrents
)
1523 if (currentTabWidget() == m_transferListWidget
)
1525 if (torrents
.contains(m_propertiesWidget
->getCurrentTorrent()))
1526 m_propertiesWidget
->loadDynamicData();
1530 /*****************************************************
1534 *****************************************************/
1536 void MainWindow::downloadFromURLList(const QStringList
&urlList
)
1538 for (const QString
&url
: urlList
)
1539 app()->addTorrentManager()->addTorrent(url
);
1542 /*****************************************************
1546 *****************************************************/
1548 QMenu
*MainWindow::createDesktopIntegrationMenu()
1550 auto *menu
= new QMenu
;
1553 connect(menu
, &QMenu::aboutToShow
, this, [this]()
1555 m_ui
->actionToggleVisibility
->setText(isVisible() ? tr("Hide") : tr("Show"));
1558 menu
->addAction(m_ui
->actionToggleVisibility
);
1559 menu
->addSeparator();
1562 menu
->addAction(m_ui
->actionOpen
);
1563 menu
->addAction(m_ui
->actionDownloadFromURL
);
1564 menu
->addSeparator();
1566 menu
->addAction(m_ui
->actionUseAlternativeSpeedLimits
);
1567 menu
->addAction(m_ui
->actionSetGlobalSpeedLimits
);
1568 menu
->addSeparator();
1570 menu
->addAction(m_ui
->actionStartAll
);
1571 menu
->addAction(m_ui
->actionPauseAll
);
1574 menu
->addSeparator();
1575 menu
->addAction(m_ui
->actionExit
);
1579 menu
->setEnabled(false);
1584 void MainWindow::updateAltSpeedsBtn(const bool alternative
)
1586 m_ui
->actionUseAlternativeSpeedLimits
->setChecked(alternative
);
1589 PropertiesWidget
*MainWindow::propertiesWidget() const
1591 return m_propertiesWidget
;
1594 // Display Program Options
1595 void MainWindow::on_actionOptions_triggered()
1599 m_options
->activateWindow();
1603 m_options
= new OptionsDialog(app(), this);
1604 m_options
->setAttribute(Qt::WA_DeleteOnClose
);
1609 void MainWindow::on_actionTopToolBar_triggered()
1611 const bool isVisible
= static_cast<QAction
*>(sender())->isChecked();
1612 m_ui
->toolBar
->setVisible(isVisible
);
1613 Preferences::instance()->setToolbarDisplayed(isVisible
);
1616 void MainWindow::on_actionShowStatusbar_triggered()
1618 const bool isVisible
= static_cast<QAction
*>(sender())->isChecked();
1619 Preferences::instance()->setStatusbarDisplayed(isVisible
);
1620 showStatusBar(isVisible
);
1623 void MainWindow::on_actionShowFiltersSidebar_triggered(const bool checked
)
1625 Preferences
*const pref
= Preferences::instance();
1626 pref
->setFiltersSidebarVisible(checked
);
1627 showFiltersSidebar(checked
);
1630 void MainWindow::on_actionSpeedInTitleBar_triggered()
1632 m_displaySpeedInTitle
= static_cast<QAction
*>(sender())->isChecked();
1633 Preferences::instance()->showSpeedInTitleBar(m_displaySpeedInTitle
);
1634 if (m_displaySpeedInTitle
)
1635 reloadSessionStats();
1637 setWindowTitle(m_windowTitle
);
1640 void MainWindow::on_actionRSSReader_triggered()
1642 Preferences::instance()->setRSSWidgetVisible(m_ui
->actionRSSReader
->isChecked());
1643 displayRSSTab(m_ui
->actionRSSReader
->isChecked());
1646 void MainWindow::on_actionSearchWidget_triggered()
1648 if (m_ui
->actionSearchWidget
->isChecked())
1650 const Utils::ForeignApps::PythonInfo pyInfo
= Utils::ForeignApps::pythonInfo();
1653 if (!pyInfo
.isValid())
1655 m_ui
->actionSearchWidget
->setChecked(false);
1656 Preferences::instance()->setSearchEnabled(false);
1659 const QMessageBox::StandardButton buttonPressed
= QMessageBox::question(this, tr("Missing Python Runtime")
1660 , tr("Python is required to use the search engine but it does not seem to be installed.\nDo you want to install it now?")
1661 , (QMessageBox::Yes
| QMessageBox::No
), QMessageBox::Yes
);
1662 if (buttonPressed
== QMessageBox::Yes
)
1665 QMessageBox::information(this, tr("Missing Python Runtime")
1666 , tr("Python is required to use the search engine but it does not seem to be installed."));
1671 // Check version requirement
1672 if (!pyInfo
.isSupportedVersion())
1674 m_ui
->actionSearchWidget
->setChecked(false);
1675 Preferences::instance()->setSearchEnabled(false);
1678 const QMessageBox::StandardButton buttonPressed
= QMessageBox::question(this, tr("Old Python Runtime")
1679 , tr("Your Python version (%1) is outdated. Minimum requirement: %2.\nDo you want to install a newer version now?")
1680 .arg(pyInfo
.version
.toString(), u
"3.7.0")
1681 , (QMessageBox::Yes
| QMessageBox::No
), QMessageBox::Yes
);
1682 if (buttonPressed
== QMessageBox::Yes
)
1685 QMessageBox::information(this, tr("Old Python Runtime")
1686 , tr("Your Python version (%1) is outdated. Please upgrade to latest version for search engines to work.\nMinimum requirement: %2.")
1687 .arg(pyInfo
.version
.toString(), u
"3.7.0"));
1692 m_ui
->actionSearchWidget
->setChecked(true);
1693 Preferences::instance()->setSearchEnabled(true);
1696 displaySearchTab(m_ui
->actionSearchWidget
->isChecked());
1699 /*****************************************************
1703 *****************************************************/
1705 // Display an input dialog to prompt user for
1707 void MainWindow::on_actionDownloadFromURL_triggered()
1709 if (!m_downloadFromURLDialog
)
1711 m_downloadFromURLDialog
= new DownloadFromURLDialog(this);
1712 m_downloadFromURLDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1713 connect(m_downloadFromURLDialog
.data(), &DownloadFromURLDialog::urlsReadyToBeDownloaded
, this, &MainWindow::downloadFromURLList
);
1714 m_downloadFromURLDialog
->open();
1718 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
1719 void MainWindow::handleUpdateCheckFinished(ProgramUpdater
*updater
, const bool invokedByUser
)
1721 m_ui
->actionCheckForUpdates
->setEnabled(true);
1722 m_ui
->actionCheckForUpdates
->setText(tr("&Check for Updates"));
1723 m_ui
->actionCheckForUpdates
->setToolTip(tr("Check for program updates"));
1725 const auto cleanup
= [this, updater
]()
1727 if (m_programUpdateTimer
)
1728 m_programUpdateTimer
->start();
1729 updater
->deleteLater();
1732 const QString newVersion
= updater
->getNewVersion();
1733 if (!newVersion
.isEmpty())
1735 const QString msg
{tr("A new version is available.") + u
"<br/>"
1736 + tr("Do you want to download %1?").arg(newVersion
) + u
"<br/><br/>"
1737 + u
"<a href=\"https://www.qbittorrent.org/news.php\">%1</a>"_s
.arg(tr("Open changelog..."))};
1738 auto *msgBox
= new QMessageBox
{QMessageBox::Question
, tr("qBittorrent Update Available"), msg
1739 , (QMessageBox::Yes
| QMessageBox::No
), this};
1740 msgBox
->setAttribute(Qt::WA_DeleteOnClose
);
1741 msgBox
->setAttribute(Qt::WA_ShowWithoutActivating
);
1742 msgBox
->setDefaultButton(QMessageBox::Yes
);
1743 msgBox
->setWindowModality(Qt::NonModal
);
1744 connect(msgBox
, &QMessageBox::buttonClicked
, this, [msgBox
, updater
](QAbstractButton
*button
)
1746 if (msgBox
->buttonRole(button
) == QMessageBox::YesRole
)
1748 updater
->updateProgram();
1751 connect(msgBox
, &QDialog::finished
, this, cleanup
);
1758 auto *msgBox
= new QMessageBox
{QMessageBox::Information
, u
"qBittorrent"_s
1759 , tr("No updates available.\nYou are already using the latest version.")
1760 , QMessageBox::Ok
, this};
1761 msgBox
->setAttribute(Qt::WA_DeleteOnClose
);
1762 msgBox
->setWindowModality(Qt::NonModal
);
1763 connect(msgBox
, &QDialog::finished
, this, cleanup
);
1774 void MainWindow::toggleAlternativeSpeeds()
1776 BitTorrent::Session
*const session
= BitTorrent::Session::instance();
1777 session
->setAltGlobalSpeedLimitEnabled(!session
->isAltGlobalSpeedLimitEnabled());
1780 void MainWindow::on_actionDonateMoney_triggered()
1782 QDesktopServices::openUrl(QUrl(u
"https://www.qbittorrent.org/donate"_s
));
1785 void MainWindow::showConnectionSettings()
1787 on_actionOptions_triggered();
1788 m_options
->showConnectionTab();
1791 void MainWindow::minimizeWindow()
1793 setWindowState(windowState() | Qt::WindowMinimized
);
1796 void MainWindow::on_actionExecutionLogs_triggered(bool checked
)
1800 Q_ASSERT(!m_executionLog
);
1801 m_executionLog
= new ExecutionLogWidget(executionLogMsgTypes(), m_tabs
);
1803 m_tabs
->addTab(m_executionLog
, tr("Execution Log"));
1805 const int indexTab
= m_tabs
->addTab(m_executionLog
, tr("Execution Log"));
1806 m_tabs
->setTabIcon(indexTab
, UIThemeManager::instance()->getIcon(u
"help-contents"_s
));
1811 delete m_executionLog
;
1814 m_ui
->actionNormalMessages
->setEnabled(checked
);
1815 m_ui
->actionInformationMessages
->setEnabled(checked
);
1816 m_ui
->actionWarningMessages
->setEnabled(checked
);
1817 m_ui
->actionCriticalMessages
->setEnabled(checked
);
1818 setExecutionLogEnabled(checked
);
1821 void MainWindow::on_actionNormalMessages_triggered(const bool checked
)
1823 if (!m_executionLog
)
1826 const Log::MsgTypes flags
= executionLogMsgTypes().setFlag(Log::NORMAL
, checked
);
1827 setExecutionLogMsgTypes(flags
);
1830 void MainWindow::on_actionInformationMessages_triggered(const bool checked
)
1832 if (!m_executionLog
)
1835 const Log::MsgTypes flags
= executionLogMsgTypes().setFlag(Log::INFO
, checked
);
1836 setExecutionLogMsgTypes(flags
);
1839 void MainWindow::on_actionWarningMessages_triggered(const bool checked
)
1841 if (!m_executionLog
)
1844 const Log::MsgTypes flags
= executionLogMsgTypes().setFlag(Log::WARNING
, checked
);
1845 setExecutionLogMsgTypes(flags
);
1848 void MainWindow::on_actionCriticalMessages_triggered(const bool checked
)
1850 if (!m_executionLog
)
1853 const Log::MsgTypes flags
= executionLogMsgTypes().setFlag(Log::CRITICAL
, checked
);
1854 setExecutionLogMsgTypes(flags
);
1857 void MainWindow::on_actionAutoExit_toggled(bool enabled
)
1859 qDebug() << Q_FUNC_INFO
<< enabled
;
1860 Preferences::instance()->setShutdownqBTWhenDownloadsComplete(enabled
);
1863 void MainWindow::on_actionAutoSuspend_toggled(bool enabled
)
1865 qDebug() << Q_FUNC_INFO
<< enabled
;
1866 Preferences::instance()->setSuspendWhenDownloadsComplete(enabled
);
1869 void MainWindow::on_actionAutoHibernate_toggled(bool enabled
)
1871 qDebug() << Q_FUNC_INFO
<< enabled
;
1872 Preferences::instance()->setHibernateWhenDownloadsComplete(enabled
);
1875 void MainWindow::on_actionAutoShutdown_toggled(bool enabled
)
1877 qDebug() << Q_FUNC_INFO
<< enabled
;
1878 Preferences::instance()->setShutdownWhenDownloadsComplete(enabled
);
1881 void MainWindow::updatePowerManagementState() const
1883 const auto *pref
= Preferences::instance();
1884 const bool preventFromSuspendWhenDownloading
= pref
->preventFromSuspendWhenDownloading();
1885 const bool preventFromSuspendWhenSeeding
= pref
->preventFromSuspendWhenSeeding();
1887 const QVector
<BitTorrent::Torrent
*> allTorrents
= BitTorrent::Session::instance()->torrents();
1888 const bool inhibitSuspend
= std::any_of(allTorrents
.cbegin(), allTorrents
.cend(), [&](const BitTorrent::Torrent
*torrent
)
1890 if (preventFromSuspendWhenDownloading
&& (!torrent
->isFinished() && !torrent
->isPaused() && !torrent
->isErrored() && torrent
->hasMetadata()))
1893 if (preventFromSuspendWhenSeeding
&& (torrent
->isFinished() && !torrent
->isPaused()))
1896 return torrent
->isMoving();
1898 m_pwr
->setActivityState(inhibitSuspend
);
1900 m_preventTimer
->start(PREVENT_SUSPEND_INTERVAL
);
1903 void MainWindow::applyTransferListFilter()
1905 m_transferListWidget
->applyFilter(m_columnFilterEdit
->text(), m_columnFilterComboBox
->currentData().value
<TransferListModel::Column
>());
1908 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
1909 void MainWindow::checkProgramUpdate(const bool invokedByUser
)
1911 if (m_programUpdateTimer
)
1912 m_programUpdateTimer
->stop();
1914 m_ui
->actionCheckForUpdates
->setEnabled(false);
1915 m_ui
->actionCheckForUpdates
->setText(tr("Checking for Updates..."));
1916 m_ui
->actionCheckForUpdates
->setToolTip(tr("Already checking for program updates in the background"));
1918 auto *updater
= new ProgramUpdater(this);
1919 connect(updater
, &ProgramUpdater::updateCheckFinished
1920 , this, [this, invokedByUser
, updater
]()
1922 handleUpdateCheckFinished(updater
, invokedByUser
);
1924 updater
->checkForUpdates();
1929 void MainWindow::installPython()
1931 setCursor(QCursor(Qt::WaitCursor
));
1933 const auto installerURL
= u
"https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe"_s
;
1934 Net::DownloadManager::instance()->download(
1935 Net::DownloadRequest(installerURL
).saveToFile(true)
1936 , Preferences::instance()->useProxyForGeneralPurposes()
1937 , this, &MainWindow::pythonDownloadFinished
);
1940 void MainWindow::pythonDownloadFinished(const Net::DownloadResult
&result
)
1942 if (result
.status
!= Net::DownloadStatus::Success
)
1944 setCursor(QCursor(Qt::ArrowCursor
));
1945 QMessageBox::warning(
1946 this, tr("Download error")
1947 , tr("Python setup could not be downloaded, reason: %1.\nPlease install it manually.")
1948 .arg(result
.errorString
));
1952 setCursor(QCursor(Qt::ArrowCursor
));
1954 qDebug("Launching Python installer in passive mode...");
1956 const Path exePath
= result
.filePath
+ u
".exe";
1957 Utils::Fs::renameFile(result
.filePath
, exePath
);
1958 installer
.start(exePath
.toString(), {u
"/passive"_s
});
1960 // Wait for setup to complete
1961 installer
.waitForFinished(10 * 60 * 1000);
1963 qDebug("Installer stdout: %s", installer
.readAllStandardOutput().data());
1964 qDebug("Installer stderr: %s", installer
.readAllStandardError().data());
1965 qDebug("Setup should be complete!");
1968 Utils::Fs::removeFile(exePath
);
1970 // Reload search engine
1971 if (Utils::ForeignApps::pythonInfo().isSupportedVersion())
1973 m_ui
->actionSearchWidget
->setChecked(true);
1974 displaySearchTab(true);