Warning, file /network/kget/mainwindow.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2002 by Patrick Charbonnier <pch@freeshell.org>
0004    Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
0005    Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
0006    Copyright (C) 2006 - 2008 Urs Wolfer <uwolfer @ kde.org>
0007    Copyright (C) 2006 Dario Massarin <nekkar@libero.it>
0008    Copyright (C) 2008 - 2011 Lukas Appelhans <l.appelhans@gmx.de>
0009    Copyright (C) 2009 - 2010 Matthias Fuchs <mat69@gmx.net>
0010 
0011    This program is free software; you can redistribute it and/or
0012    modify it under the terms of the GNU General Public
0013    License as published by the Free Software Foundation; either
0014    version 2 of the License, or (at your option) any later version.
0015 */
0016 
0017 #include "mainwindow.h"
0018 
0019 #include "conf/autopastemodel.h"
0020 #include "conf/preferencesdialog.h"
0021 #include "core/kget.h"
0022 #include "core/transfergrouphandler.h"
0023 #include "core/transferhandler.h"
0024 #include "core/transfertreemodel.h"
0025 #include "core/transfertreeselectionmodel.h"
0026 #include "core/verifier.h"
0027 #include "settings.h"
0028 #include "ui/droptarget.h"
0029 #include "ui/groupsettingsdialog.h"
0030 #include "ui/history/transferhistory.h"
0031 #include "ui/linkview/kget_linkview.h"
0032 #include "ui/metalinkcreator/metalinkcreator.h"
0033 #include "ui/newtransferdialog.h"
0034 #include "ui/transfersettingsdialog.h"
0035 #include "ui/viewscontainer.h"
0036 #ifdef DO_KGET_TEST
0037 #include "tests/testkget.h"
0038 #endif
0039 
0040 #include "kget_debug.h"
0041 #include <QDebug>
0042 
0043 #include <KActionMenu>
0044 #include <KIconDialog>
0045 #include <KLocalizedString>
0046 #include <KMessageBox>
0047 #include <KNotifyConfigWidget>
0048 #include <KRun>
0049 #include <KSelectAction>
0050 #include <KStandardAction>
0051 #include <kwidgetsaddons_version.h>
0052 
0053 #include <QApplication>
0054 #include <QClipboard>
0055 #include <QFileDialog>
0056 #include <QIcon>
0057 #include <QInputDialog>
0058 #include <QKeySequence>
0059 #include <QMenuBar>
0060 #include <QSessionManager>
0061 #include <QStandardPaths>
0062 #include <QTimer>
0063 #ifdef DO_KGET_TEST
0064 #include <QtTest>
0065 #endif
0066 
0067 MainWindow::MainWindow(bool showMainwindow, bool startWithoutAnimation, bool doTesting, QWidget *parent)
0068     : KXmlGuiWindow(parent)
0069     , m_drop(nullptr)
0070     , m_dock(nullptr)
0071     , clipboardTimer(nullptr)
0072     , m_startWithoutAnimation(startWithoutAnimation)
0073     , m_doTesting(doTesting) /*,
0074        m_webinterface(nullptr)*/
0075 {
0076     // do not quit the app when it has been minimized to system tray and a new transfer dialog
0077     // gets opened and closed again.
0078     qApp->setQuitOnLastWindowClosed(false);
0079     setAttribute(Qt::WA_DeleteOnClose, false);
0080 
0081     // create the model
0082     m_kget = KGet::self(this);
0083 
0084     m_viewsContainer = new ViewsContainer(this);
0085 
0086     // create actions
0087     setupActions();
0088 
0089     setupGUI(ToolBar | Keys | Save | Create);
0090 
0091     setCentralWidget(m_viewsContainer);
0092 
0093     // restore position, size and visibility
0094     move(Settings::mainPosition());
0095     setPlainCaption(i18n("KGet"));
0096 
0097     init();
0098 
0099     if (Settings::showMain() && showMainwindow)
0100         show();
0101     else
0102         hide();
0103 }
0104 
0105 MainWindow::~MainWindow()
0106 {
0107     // Save the user's transfers
0108     KGet::save();
0109 
0110     slotSaveMyself();
0111     // reset konqueror integration (necessary if user enabled / disabled temporarily integration from tray)
0112     slotKonquerorIntegration(Settings::konquerorIntegration());
0113     // the following call saves options set in above dtors
0114     Settings::self()->save();
0115 
0116     delete m_drop;
0117     delete m_kget;
0118 }
0119 
0120 QSize MainWindow::sizeHint() const
0121 {
0122     return QSize(738, 380);
0123 }
0124 
0125 int MainWindow::transfersPercent()
0126 {
0127     int percent = 0;
0128     int activeTransfers = 0;
0129     foreach (const TransferHandler *handler, KGet::allTransfers()) {
0130         if (handler->status() == Job::Running) {
0131             activeTransfers++;
0132             percent += handler->percent();
0133         }
0134     }
0135 
0136     if (activeTransfers > 0) {
0137         return percent / activeTransfers;
0138     } else {
0139         return -1;
0140     }
0141 }
0142 
0143 void MainWindow::setupActions()
0144 {
0145     QAction *newDownloadAction = actionCollection()->addAction("new_download");
0146     newDownloadAction->setText(i18n("&New Download..."));
0147     newDownloadAction->setIcon(QIcon::fromTheme("document-new"));
0148     // newDownloadAction->setHelpText(i18n("Opens a dialog to add a transfer to the list"));
0149     actionCollection()->setDefaultShortcut(newDownloadAction, QKeySequence(Qt::CTRL + Qt::Key_N));
0150     connect(newDownloadAction, &QAction::triggered, this, &MainWindow::slotNewTransfer);
0151 
0152     QAction *openAction = actionCollection()->addAction("import_transfers");
0153     openAction->setText(i18n("&Import Transfers..."));
0154     openAction->setIcon(QIcon::fromTheme("document-open"));
0155     // openAction->setHelpText(i18n("Imports a list of transfers"));
0156     actionCollection()->setDefaultShortcut(openAction, QKeySequence(Qt::CTRL + Qt::Key_I));
0157     connect(openAction, &QAction::triggered, this, &MainWindow::slotImportTransfers);
0158 
0159     QAction *exportAction = actionCollection()->addAction("export_transfers");
0160     exportAction->setText(i18n("&Export Transfers List..."));
0161     exportAction->setIcon(QIcon::fromTheme("document-export"));
0162     // exportAction->setHelpText(i18n("Exports the current transfers into a file"));
0163     actionCollection()->setDefaultShortcut(exportAction, QKeySequence(Qt::CTRL + Qt::Key_E));
0164     connect(exportAction, &QAction::triggered, this, &MainWindow::slotExportTransfers);
0165 
0166     QAction *createMetalinkAction = actionCollection()->addAction("create_metalink");
0167     createMetalinkAction->setText(i18n("&Create a Metalink..."));
0168     createMetalinkAction->setIcon(QIcon::fromTheme("journal-new"));
0169     // createMetalinkAction->setHelpText(i18n("Creates or modifies a metalink and saves it on disk"));
0170     connect(createMetalinkAction, &QAction::triggered, this, &MainWindow::slotCreateMetalink);
0171 
0172     QAction *priorityTop = actionCollection()->addAction("priority_top");
0173     priorityTop->setText(i18n("Top Priority"));
0174     priorityTop->setIcon(QIcon::fromTheme("arrow-up-double"));
0175     // priorityTop->setHelpText(i18n("Download selected transfer first"));
0176     actionCollection()->setDefaultShortcut(priorityTop, QKeySequence(Qt::CTRL + Qt::Key_PageUp));
0177     connect(priorityTop, &QAction::triggered, this, &MainWindow::slotPriorityTop);
0178 
0179     QAction *priorityBottom = actionCollection()->addAction("priority_bottom");
0180     priorityBottom->setText(i18n("Least Priority"));
0181     priorityBottom->setIcon(QIcon::fromTheme("arrow-down-double"));
0182     // priorityBottom->setHelpText(i18n("Download selected transfer last"));
0183     actionCollection()->setDefaultShortcut(priorityBottom, QKeySequence(Qt::CTRL + Qt::Key_PageDown));
0184     connect(priorityBottom, &QAction::triggered, this, &MainWindow::slotPriorityBottom);
0185 
0186     QAction *priorityUp = actionCollection()->addAction("priority_up");
0187     priorityUp->setText(i18n("Increase Priority"));
0188     priorityUp->setIcon(QIcon::fromTheme("arrow-up"));
0189     // priorityUp->setHelpText(i18n("Increase priority for selected transfer"));
0190     actionCollection()->setDefaultShortcut(priorityUp, QKeySequence(Qt::CTRL + Qt::Key_Up));
0191     connect(priorityUp, &QAction::triggered, this, &MainWindow::slotPriorityUp);
0192 
0193     QAction *priorityDown = actionCollection()->addAction("priority_down");
0194     priorityDown->setText(i18n("Decrease Priority"));
0195     priorityDown->setIcon(QIcon::fromTheme("arrow-down"));
0196     // priorityDown->setHelpText(i18n("Decrease priority for selected transfer"));
0197     actionCollection()->setDefaultShortcut(priorityDown, QKeySequence(Qt::CTRL + Qt::Key_Down));
0198     connect(priorityDown, &QAction::triggered, this, &MainWindow::slotPriorityDown);
0199 
0200     // FIXME: Not needed maybe because the normal delete already deletes groups?
0201     QAction *deleteGroupAction = actionCollection()->addAction("delete_groups");
0202     deleteGroupAction->setText(i18nc("@action", "Delete Group"));
0203     deleteGroupAction->setIcon(QIcon::fromTheme("edit-delete"));
0204     // deleteGroupAction->setHelpText(i18n("Delete selected group"));
0205     connect(deleteGroupAction, &QAction::triggered, this, &MainWindow::slotDeleteGroup);
0206 
0207     QAction *renameGroupAction = actionCollection()->addAction("rename_groups");
0208     renameGroupAction->setText(i18nc("@action", "Rename Group..."));
0209     renameGroupAction->setIcon(QIcon::fromTheme("edit-rename"));
0210     connect(renameGroupAction, &QAction::triggered, this, &MainWindow::slotRenameGroup);
0211 
0212     QAction *setIconGroupAction = actionCollection()->addAction("seticon_groups");
0213     setIconGroupAction->setText(i18n("Set Icon..."));
0214     setIconGroupAction->setIcon(QIcon::fromTheme("preferences-desktop-icons"));
0215     // setIconGroupAction->setHelpText(i18n("Select a custom icon for the selected group"));
0216     connect(setIconGroupAction, &QAction::triggered, this, &MainWindow::slotSetIconGroup);
0217 
0218     m_autoPasteAction = new KToggleAction(QIcon::fromTheme("edit-paste"), i18n("Auto-Paste Mode"), actionCollection());
0219     actionCollection()->addAction("auto_paste", m_autoPasteAction);
0220     m_autoPasteAction->setChecked(Settings::autoPaste());
0221     m_autoPasteAction->setWhatsThis(
0222         i18n("<b>Auto paste</b> button toggles the auto-paste mode "
0223              "on and off.\nWhen set, KGet will periodically scan "
0224              "the clipboard for URLs and paste them automatically."));
0225     connect(m_autoPasteAction, &QAction::triggered, this, &MainWindow::slotToggleAutoPaste);
0226 
0227     m_konquerorIntegration = new KToggleAction(QIcon::fromTheme("konqueror"), i18n("Use KGet as Konqueror Download Manager"), actionCollection());
0228     actionCollection()->addAction("konqueror_integration", m_konquerorIntegration);
0229     connect(m_konquerorIntegration, &QAction::triggered, this, &MainWindow::slotTrayKonquerorIntegration);
0230     m_konquerorIntegration->setChecked(Settings::konquerorIntegration());
0231 
0232     // local - Destroys all sub-windows and exits
0233     KStandardAction::quit(this, SLOT(slotQuit()), actionCollection());
0234     // local - Standard configure actions
0235     KStandardAction::preferences(this, SLOT(slotPreferences()), actionCollection());
0236 
0237     KStandardAction::configureNotifications(this, SLOT(slotConfigureNotifications()), actionCollection());
0238     m_menubarAction = KStandardAction::showMenubar(this, SLOT(slotShowMenubar()), actionCollection());
0239     m_menubarAction->setChecked(!menuBar()->isHidden());
0240 
0241     // Transfer related actions
0242     actionCollection()->addAction(KStandardAction::SelectAll, "select_all", m_viewsContainer, SLOT(selectAll()));
0243 
0244     QAction *deleteSelectedAction = actionCollection()->addAction("delete_selected_download");
0245     deleteSelectedAction->setText(i18nc("delete selected transfer item", "Remove Selected"));
0246     deleteSelectedAction->setIcon(QIcon::fromTheme("edit-delete"));
0247     //     deleteSelectedAction->setHelpText(i18n("Removes selected transfer and deletes files from disk if it's not finished"));
0248     actionCollection()->setDefaultShortcut(deleteSelectedAction, QKeySequence(Qt::Key_Delete));
0249     connect(deleteSelectedAction, &QAction::triggered, this, &MainWindow::slotDeleteSelected);
0250 
0251     QAction *deleteAllFinishedAction = actionCollection()->addAction("delete_all_finished");
0252     deleteAllFinishedAction->setText(i18nc("delete all finished transfers", "Remove All Finished"));
0253     deleteAllFinishedAction->setIcon(QIcon::fromTheme("edit-clear-list"));
0254     //     deleteAllFinishedAction->setHelpText(i18n("Removes all finished transfers and leaves all files on disk"));
0255     connect(deleteAllFinishedAction, &QAction::triggered, this, &MainWindow::slotDeleteFinished);
0256 
0257     QAction *deleteSelectedIncludingFilesAction = actionCollection()->addAction("delete_selected_download_including_files");
0258     deleteSelectedIncludingFilesAction->setText(i18nc("delete selected transfer item and files", "Remove Selected and Delete Files"));
0259     deleteSelectedIncludingFilesAction->setIcon(QIcon::fromTheme("edit-delete"));
0260     //     deleteSelectedIncludingFilesAction->setHelpText(i18n("Removes selected transfer and deletes files from disk in any case"));
0261     connect(deleteSelectedIncludingFilesAction, &QAction::triggered, this, &MainWindow::slotDeleteSelectedIncludingFiles);
0262 
0263     QAction *redownloadSelectedAction = actionCollection()->addAction("redownload_selected_download");
0264     redownloadSelectedAction->setText(i18nc("redownload selected transfer item", "Redownload Selected"));
0265     redownloadSelectedAction->setIcon(QIcon::fromTheme("view-refresh"));
0266     connect(redownloadSelectedAction, &QAction::triggered, this, &MainWindow::slotRedownloadSelected);
0267 
0268     QAction *startAllAction = actionCollection()->addAction("start_all_download");
0269     startAllAction->setText(i18n("Start All"));
0270     startAllAction->setIcon(QIcon::fromTheme("media-seek-forward"));
0271     //     startAllAction->setHelpText(i18n("Starts / resumes all transfers"));
0272     actionCollection()->setDefaultShortcut(startAllAction, QKeySequence(Qt::CTRL + Qt::Key_R));
0273     connect(startAllAction, &QAction::triggered, this, &MainWindow::slotStartAllDownload);
0274 
0275     QAction *startSelectedAction = actionCollection()->addAction("start_selected_download");
0276     startSelectedAction->setText(i18n("Start Selected"));
0277     startSelectedAction->setIcon(QIcon::fromTheme("media-playback-start"));
0278     //     startSelectedAction->setHelpText(i18n("Starts / resumes selected transfer"));
0279     connect(startSelectedAction, &QAction::triggered, this, &MainWindow::slotStartSelectedDownload);
0280 
0281     QAction *stopAllAction = actionCollection()->addAction("stop_all_download");
0282     stopAllAction->setText(i18n("Pause All"));
0283     stopAllAction->setIcon(QIcon::fromTheme("media-playback-pause"));
0284     //     stopAllAction->setHelpText(i18n("Pauses all transfers"));
0285     actionCollection()->setDefaultShortcut(stopAllAction, QKeySequence(Qt::CTRL + Qt::Key_P));
0286     connect(stopAllAction, &QAction::triggered, this, &MainWindow::slotStopAllDownload);
0287 
0288     QAction *stopSelectedAction = actionCollection()->addAction("stop_selected_download");
0289     stopSelectedAction->setText(i18n("Stop Selected"));
0290     stopSelectedAction->setIcon(QIcon::fromTheme("media-playback-pause"));
0291     // stopSelectedAction->setHelpText(i18n("Pauses selected transfer"));
0292     connect(stopSelectedAction, &QAction::triggered, this, &MainWindow::slotStopSelectedDownload);
0293 
0294     auto *startActionMenu = new KActionMenu(QIcon::fromTheme("media-playback-start"), i18n("Start"), actionCollection());
0295     actionCollection()->addAction("start_menu", startActionMenu);
0296     startActionMenu->setPopupMode(QToolButton::DelayedPopup);
0297     startActionMenu->addAction(startSelectedAction);
0298     startActionMenu->addAction(startAllAction);
0299     connect(startActionMenu, &QAction::triggered, this, &MainWindow::slotStartDownload);
0300 
0301     auto *stopActionMenu = new KActionMenu(QIcon::fromTheme("media-playback-pause"), i18n("Pause"), actionCollection());
0302     actionCollection()->addAction("stop_menu", stopActionMenu);
0303     stopActionMenu->setPopupMode(QToolButton::DelayedPopup);
0304     stopActionMenu->addAction(stopSelectedAction);
0305     stopActionMenu->addAction(stopAllAction);
0306     connect(stopActionMenu, &QAction::triggered, this, &MainWindow::slotStopDownload);
0307 
0308     QAction *openDestAction = actionCollection()->addAction("transfer_open_dest");
0309     openDestAction->setText(i18n("Open Destination"));
0310     openDestAction->setIcon(QIcon::fromTheme("document-open"));
0311     connect(openDestAction, &QAction::triggered, this, &MainWindow::slotTransfersOpenDest);
0312 
0313     QAction *openFileAction = actionCollection()->addAction("transfer_open_file");
0314     openFileAction->setText(i18n("Open File"));
0315     openFileAction->setIcon(QIcon::fromTheme("document-open"));
0316     connect(openFileAction, &QAction::triggered, this, &MainWindow::slotTransfersOpenFile);
0317 
0318     QAction *showDetailsAction = new KToggleAction(QIcon::fromTheme("document-properties"), i18n("Show Details"), actionCollection());
0319     actionCollection()->addAction("transfer_show_details", showDetailsAction);
0320     connect(showDetailsAction, &QAction::triggered, this, &MainWindow::slotTransfersShowDetails);
0321 
0322     QAction *copyUrlAction = actionCollection()->addAction("transfer_copy_source_url");
0323     copyUrlAction->setText(i18n("Copy URL to Clipboard"));
0324     copyUrlAction->setIcon(QIcon::fromTheme("edit-copy"));
0325     connect(copyUrlAction, &QAction::triggered, this, &MainWindow::slotTransfersCopySourceUrl);
0326 
0327     QAction *transferHistoryAction = actionCollection()->addAction("transfer_history");
0328     transferHistoryAction->setText(i18n("&Transfer History"));
0329     transferHistoryAction->setIcon(QIcon::fromTheme("view-history"));
0330     actionCollection()->setDefaultShortcut(transferHistoryAction, QKeySequence(Qt::CTRL + Qt::Key_H));
0331     connect(transferHistoryAction, &QAction::triggered, this, &MainWindow::slotTransferHistory);
0332 
0333     QAction *transferGroupSettingsAction = actionCollection()->addAction("transfer_group_settings");
0334     transferGroupSettingsAction->setText(i18n("&Group Settings"));
0335     transferGroupSettingsAction->setIcon(QIcon::fromTheme("preferences-system"));
0336     actionCollection()->setDefaultShortcut(transferGroupSettingsAction, QKeySequence(Qt::CTRL + Qt::Key_G));
0337     connect(transferGroupSettingsAction, &QAction::triggered, this, &MainWindow::slotTransferGroupSettings);
0338 
0339     QAction *transferSettingsAction = actionCollection()->addAction("transfer_settings");
0340     transferSettingsAction->setText(i18n("&Transfer Settings"));
0341     transferSettingsAction->setIcon(QIcon::fromTheme("preferences-system"));
0342     actionCollection()->setDefaultShortcut(transferSettingsAction, QKeySequence(Qt::CTRL + Qt::Key_T));
0343     connect(transferSettingsAction, &QAction::triggered, this, &MainWindow::slotTransferSettings);
0344 
0345     QAction *listLinksAction = actionCollection()->addAction("import_links");
0346     listLinksAction->setText(i18n("Import &Links..."));
0347     listLinksAction->setIcon(QIcon::fromTheme("view-list-text"));
0348     actionCollection()->setDefaultShortcut(listLinksAction, QKeySequence(Qt::CTRL + Qt::Key_L));
0349     connect(listLinksAction, &QAction::triggered, this, &MainWindow::slotShowListLinks);
0350 
0351     // create the download finished actions which can be displayed in the toolbar
0352     auto *downloadFinishedActions = new KSelectAction(i18n("After downloads finished action"), this); // TODO maybe with name??
0353     actionCollection()->addAction("download_finished_actions", downloadFinishedActions);
0354     // downloadFinishedActions->setHelpText(i18n("Choose an action that is executed after all downloads have been finished."));
0355 
0356     QAction *noAction = downloadFinishedActions->addAction(i18n("No Action"));
0357     connect(noAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0358     downloadFinishedActions->addAction(noAction);
0359 
0360     QAction *quitAction = downloadFinishedActions->addAction(i18n("Quit KGet"));
0361     quitAction->setData(KGet::Quit);
0362     connect(quitAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0363     downloadFinishedActions->addAction(quitAction);
0364 
0365 #ifdef HAVE_KWORKSPACE
0366     QAction *shutdownAction = downloadFinishedActions->addAction(i18n("Turn Off Computer"));
0367     shutdownAction->setData(KGet::Shutdown);
0368     connect(shutdownAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0369     downloadFinishedActions->addAction(shutdownAction);
0370 
0371     QAction *hibernateAction = downloadFinishedActions->addAction(i18n("Hibernate Computer"));
0372     hibernateAction->setData(KGet::Hibernate);
0373     connect(hibernateAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0374     downloadFinishedActions->addAction(hibernateAction);
0375 
0376     QAction *suspendAction = downloadFinishedActions->addAction(i18n("Suspend Computer"));
0377     suspendAction->setData(KGet::Suspend);
0378     connect(suspendAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0379     downloadFinishedActions->addAction(suspendAction);
0380 #endif
0381 
0382     if (Settings::afterFinishActionEnabled()) {
0383         downloadFinishedActions->setCurrentItem(Settings::afterFinishAction() + 1);
0384     } else {
0385         downloadFinishedActions->setCurrentItem(0);
0386     }
0387 }
0388 
0389 void MainWindow::slotDownloadFinishedActions()
0390 {
0391     auto *action = static_cast<QAction *>(QObject::sender());
0392     bool ok;
0393     const int type = action->data().toInt(&ok);
0394     if (ok) {
0395         Settings::self()->setAfterFinishAction(type);
0396     }
0397 
0398     // only after finish actions have a number assigned
0399     Settings::self()->setAfterFinishActionEnabled(ok);
0400     Settings::self()->save();
0401     slotNewConfig();
0402 }
0403 
0404 void MainWindow::init()
0405 {
0406     // Here we import the user's transfers.
0407     KGet::load(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/transfers.kgt"));
0408 
0409     if (Settings::enableSystemTray()) {
0410         m_dock = new Tray(this);
0411     }
0412 
0413     // enable dropping
0414     setAcceptDrops(true);
0415 
0416     // enable hide toolbar
0417     setStandardToolBarMenuEnabled(true);
0418 
0419     // session management stuff
0420     auto disableSessionManagement = [](QSessionManager &sm) {
0421         sm.setRestartHint(QSessionManager::RestartNever);
0422     };
0423     QObject::connect(qApp, &QGuiApplication::saveStateRequest, disableSessionManagement);
0424 
0425     // set auto-resume in kioslaverc (is there a cleaner way?)
0426     KConfig cfg("kioslaverc", KConfig::NoGlobals);
0427     cfg.group(QString()).writeEntry("AutoResume", true);
0428     cfg.sync();
0429 
0430     // DropTarget
0431     m_drop = new DropTarget(this);
0432 
0433     if (Settings::firstRun()) {
0434 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0435         if (KMessageBox::questionTwoActions(this,
0436 #else
0437         if (KMessageBox::questionYesNo(this,
0438 #endif
0439                                             i18n("This is the first time you have run KGet.\n"
0440                                                  "Would you like to enable KGet as the download manager for Konqueror?"),
0441                                             i18n("Konqueror Integration"),
0442                                             KGuiItem(i18n("Enable")),
0443                                             KGuiItem(i18n("Do Not Enable")))
0444 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0445             == KMessageBox::PrimaryAction) {
0446 #else
0447             == KMessageBox::Yes) {
0448 #endif
0449             Settings::setKonquerorIntegration(true);
0450             m_konquerorIntegration->setChecked(Settings::konquerorIntegration());
0451             slotKonquerorIntegration(true);
0452         }
0453 
0454         m_drop->setDropTargetVisible(false);
0455 
0456         // reset the FirstRun config option
0457         Settings::setFirstRun(false);
0458     }
0459 
0460     if (Settings::showDropTarget() && !m_startWithoutAnimation)
0461         m_drop->setDropTargetVisible(true);
0462 
0463     // auto paste stuff
0464     lastClipboard = QApplication::clipboard()->text(QClipboard::Clipboard).trimmed();
0465     clipboardTimer = new QTimer(this);
0466     connect(clipboardTimer, &QTimer::timeout, this, &MainWindow::slotCheckClipboard);
0467     if (Settings::autoPaste())
0468         clipboardTimer->start(1000);
0469 
0470     /*if (Settings::webinterfaceEnabled())
0471         m_webinterface = new HttpServer(this);*///TODO: Port to KF5
0472 
0473     if (Settings::speedLimit()) {
0474         KGet::setGlobalDownloadLimit(Settings::globalDownloadLimit());
0475         KGet::setGlobalUploadLimit(Settings::globalUploadLimit());
0476     } else {
0477         KGet::setGlobalDownloadLimit(0);
0478         KGet::setGlobalUploadLimit(0);
0479     }
0480 
0481     connect(KGet::model(), &TransferTreeModel::transfersAddedEvent, this, &MainWindow::slotUpdateTitlePercent);
0482     connect(KGet::model(), &TransferTreeModel::transfersRemovedEvent, this, &MainWindow::slotUpdateTitlePercent);
0483     connect(KGet::model(),
0484             SIGNAL(transfersChangedEvent(QMap<TransferHandler *, Transfer::ChangesFlags>)),
0485             SLOT(slotTransfersChanged(QMap<TransferHandler *, Transfer::ChangesFlags>)));
0486     connect(KGet::model(),
0487             SIGNAL(groupsChangedEvent(QMap<TransferGroupHandler *, TransferGroup::ChangesFlags>)),
0488             SLOT(slotGroupsChanged(QMap<TransferGroupHandler *, TransferGroup::ChangesFlags>)));
0489 
0490 #ifdef DO_KGET_TEST
0491     if (m_doTesting) {
0492         // Unit testing
0493         TestKGet unitTest;
0494         QTest::qExec(&unitTest);
0495     }
0496 #endif
0497 }
0498 
0499 void MainWindow::slotToggleDropTarget()
0500 {
0501     m_drop->setDropTargetVisible(!m_drop->isVisible());
0502 }
0503 
0504 void MainWindow::slotNewTransfer()
0505 {
0506     NewTransferDialogHandler::showNewTransferDialog(QUrl());
0507 }
0508 
0509 void MainWindow::slotImportTransfers()
0510 {
0511     QString filename = QFileDialog::getOpenFileName(nullptr,
0512                                                     i18nc("@title:window", "Open File"),
0513                                                     QString(),
0514                                                     i18n("All Openable Files") + " (*.kgt *.metalink *.meta4 *.torrent)");
0515 
0516     if (filename.endsWith(QLatin1String(".kgt"))) {
0517         KGet::load(filename);
0518         return;
0519     }
0520 
0521     if (!filename.isEmpty())
0522         KGet::addTransfer(QUrl(filename));
0523 }
0524 
0525 void MainWindow::slotUpdateTitlePercent()
0526 {
0527     int percent = transfersPercent();
0528     if (percent != -1) {
0529         setPlainCaption(i18nc("window title including overall download progress in percent", "KGet - %1%", percent));
0530     } else {
0531         setPlainCaption(i18n("KGet"));
0532     }
0533 }
0534 
0535 void MainWindow::slotTransfersChanged(QMap<TransferHandler *, Transfer::ChangesFlags> transfers)
0536 {
0537     QMapIterator<TransferHandler *, Transfer::ChangesFlags> it(transfers);
0538 
0539     // QList<TransferHandler *> finishedTransfers;
0540     bool update = false;
0541 
0542     while (it.hasNext()) {
0543         it.next();
0544 
0545         // TransferHandler * transfer = it.key();
0546         Transfer::ChangesFlags transferFlags = it.value();
0547 
0548         if (transferFlags & Transfer::Tc_Percent || transferFlags & Transfer::Tc_Status) {
0549             update = true;
0550             break;
0551         }
0552 
0553         //         qCDebug(KGET_DEBUG) << it.key() << ": " << it.value() << endl;
0554     }
0555 
0556     if (update)
0557         slotUpdateTitlePercent();
0558 }
0559 
0560 void MainWindow::slotGroupsChanged(QMap<TransferGroupHandler *, TransferGroup::ChangesFlags> groups)
0561 {
0562     bool update = false;
0563     foreach (const TransferGroup::ChangesFlags &groupFlags, groups) {
0564         if (groupFlags & TransferGroup::Gc_Percent) {
0565             update = true;
0566             break;
0567         }
0568     }
0569     if (update)
0570         slotUpdateTitlePercent();
0571 }
0572 
0573 void MainWindow::slotQuit()
0574 {
0575     if (KGet::schedulerRunning()) {
0576 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0577         if (KMessageBox::warningTwoActions(this,
0578 #else
0579         if (KMessageBox::warningYesNo(this,
0580 #endif
0581                                            i18n("Some transfers are still running.\n"
0582                                                 "Are you sure you want to close KGet?"),
0583                                            i18n("Confirm Quit"),
0584                                            KStandardGuiItem::quit(),
0585                                            KStandardGuiItem::cancel(),
0586                                            "ExitWithActiveTransfers")
0587 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0588             == KMessageBox::SecondaryAction)
0589 #else
0590             == KMessageBox::No)
0591 #endif
0592             return;
0593     }
0594 
0595     Settings::self()->save();
0596     qApp->quit();
0597 }
0598 
0599 void MainWindow::slotPreferences()
0600 {
0601     // never reuse the preference dialog, to make sure its settings are always reloaded
0602     auto *dialog = new PreferencesDialog(this, Settings::self());
0603     dialog->setAttribute(Qt::WA_DeleteOnClose);
0604 
0605     // keep us informed when the user changes settings
0606     connect(dialog, &KConfigDialog::settingsChanged, this, &MainWindow::slotNewConfig);
0607 
0608     dialog->show();
0609 }
0610 
0611 void MainWindow::slotExportTransfers()
0612 {
0613     const QString filename = QFileDialog::getSaveFileName(this,
0614                                                           i18nc("@title:window", "Export Transfers"),
0615                                                           QString(),
0616                                                           i18n("KGet Transfer List") + " (*.kgt);;" + i18n("Text File") + " (*.txt)");
0617 
0618     if (!filename.isEmpty()) {
0619         const bool plain = !filename.endsWith(QLatin1String(".kgt"));
0620         KGet::save(filename, plain);
0621     }
0622 }
0623 
0624 void MainWindow::slotCreateMetalink()
0625 {
0626     auto *dialog = new MetalinkCreator(this);
0627     dialog->setAttribute(Qt::WA_DeleteOnClose);
0628     dialog->show();
0629 }
0630 
0631 void MainWindow::slotDeleteGroup()
0632 {
0633     QList<TransferGroupHandler *> groups = KGet::selectedTransferGroups();
0634     if (groups.count() != KGet::allTransferGroups().count()) {
0635         KGet::delGroups(groups);
0636     }
0637 }
0638 
0639 void MainWindow::slotRenameGroup()
0640 {
0641     bool ok = true;
0642     QString groupName;
0643 
0644     foreach (TransferGroupHandler *it, KGet::selectedTransferGroups()) {
0645         groupName = QInputDialog::getText(this, i18n("Enter Group Name"), i18n("Group name:"), QLineEdit::Normal, it->name(), &ok);
0646         if (ok)
0647             it->setName(groupName);
0648     }
0649 }
0650 
0651 void MainWindow::slotSetIconGroup()
0652 {
0653     KIconDialog dialog(this);
0654     QString iconName = dialog.getIcon();
0655     TransferTreeSelectionModel *selModel = KGet::selectionModel();
0656 
0657     QModelIndexList indexList = selModel->selectedRows();
0658 
0659     if (!iconName.isEmpty()) {
0660         foreach (TransferGroupHandler *group, KGet::selectedTransferGroups()) {
0661             group->setIconName(iconName);
0662         }
0663     }
0664     // Q_EMIT dataChanged(indexList.first(),indexList.last());
0665 }
0666 
0667 void MainWindow::slotStartDownload()
0668 {
0669     if (KGet::selectedTransfers().size() == 0 && KGet::selectedTransferGroups().size() == 0) {
0670         slotStartAllDownload();
0671     } else {
0672         slotStartSelectedDownload();
0673     }
0674 }
0675 
0676 void MainWindow::slotStartAllDownload()
0677 {
0678     KGet::setSchedulerRunning(true);
0679 }
0680 
0681 void MainWindow::slotStartSelectedDownload()
0682 {
0683     KGet::setSuspendScheduler(true);
0684     foreach (TransferHandler *transfer, KGet::selectedTransfers()) {
0685         transfer->start();
0686     }
0687     foreach (TransferGroupHandler *group, KGet::selectedTransferGroups()) {
0688         group->start();
0689     }
0690     KGet::setSuspendScheduler(false);
0691 }
0692 
0693 void MainWindow::slotStopDownload()
0694 {
0695     if (KGet::selectedTransfers().size() == 0 && KGet::selectedTransferGroups().size() == 0) {
0696         slotStopAllDownload();
0697     } else {
0698         slotStopSelectedDownload();
0699     }
0700 }
0701 
0702 void MainWindow::slotStopAllDownload()
0703 {
0704     KGet::setSchedulerRunning(false);
0705 
0706     // This line ensures that each transfer is stopped. In the handler class
0707     // the policy of the transfer will be correctly set to None
0708     foreach (TransferHandler *it, KGet::allTransfers())
0709         it->stop();
0710 }
0711 
0712 void MainWindow::slotStopSelectedDownload()
0713 {
0714     KGet::setSuspendScheduler(true);
0715     foreach (TransferHandler *transfer, KGet::selectedTransfers()) {
0716         transfer->stop();
0717     }
0718     foreach (TransferGroupHandler *group, KGet::selectedTransferGroups()) {
0719         group->stop();
0720     }
0721     KGet::setSuspendScheduler(false);
0722 }
0723 
0724 void MainWindow::slotDeleteSelected()
0725 {
0726     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0727         if (it->status() != Job::Finished && it->status() != Job::FinishedKeepAlive) {
0728 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0729             if (KMessageBox::warningTwoActions(this,
0730 #else
0731             if (KMessageBox::warningYesNo(this,
0732 #endif
0733                                                i18np("Are you sure you want to delete the selected transfer?",
0734                                                      "Are you sure you want to delete the selected transfers?",
0735                                                      KGet::selectedTransfers().count()),
0736                                                i18n("Confirm transfer delete"),
0737                                                KStandardGuiItem::remove(),
0738                                                KStandardGuiItem::cancel())
0739 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0740                 == KMessageBox::SecondaryAction)
0741 #else
0742                 == KMessageBox::No)
0743 #endif
0744             {
0745                 return;
0746             }
0747             break;
0748         }
0749     }
0750 
0751     const QList<TransferHandler *> selectedTransfers = KGet::selectedTransfers();
0752     if (!selectedTransfers.isEmpty()) {
0753         foreach (TransferHandler *it, selectedTransfers) {
0754             m_viewsContainer->closeTransferDetails(it); // TODO make it take QList?
0755         }
0756         KGet::delTransfers(KGet::selectedTransfers());
0757     } else {
0758         // no transfers selected, delete groups if any are selected
0759         slotDeleteGroup();
0760     }
0761 }
0762 
0763 void MainWindow::slotDeleteSelectedIncludingFiles()
0764 {
0765     const QList<TransferHandler *> selectedTransfers = KGet::selectedTransfers();
0766 
0767     if (!selectedTransfers.isEmpty()) {
0768 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0769         if (KMessageBox::warningTwoActions(this,
0770 #else
0771         if (KMessageBox::warningYesNo(this,
0772 #endif
0773                                            i18np("Are you sure you want to delete the selected transfer including files?",
0774                                                  "Are you sure you want to delete the selected transfers including files?",
0775                                                  selectedTransfers.count()),
0776                                            i18n("Confirm transfer delete"),
0777                                            KStandardGuiItem::remove(),
0778                                            KStandardGuiItem::cancel())
0779 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0780             == KMessageBox::SecondaryAction) {
0781 #else
0782             == KMessageBox::No) {
0783 #endif
0784             return;
0785         }
0786         foreach (TransferHandler *it, selectedTransfers) {
0787             m_viewsContainer->closeTransferDetails(it); // TODO make it take QList?
0788         }
0789         KGet::delTransfers(KGet::selectedTransfers(), KGet::DeleteFiles);
0790     } else {
0791         // no transfers selected, delete groups if any are selected
0792         slotDeleteGroup();
0793     }
0794 }
0795 
0796 void MainWindow::slotRedownloadSelected()
0797 {
0798     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0799         KGet::redownloadTransfer(it);
0800     }
0801 }
0802 
0803 void MainWindow::slotPriorityTop()
0804 {
0805     QList<TransferHandler *> selected = KGet::selectedTransfers();
0806     TransferHandler *after = nullptr;
0807     TransferGroupHandler *group = nullptr;
0808     foreach (TransferHandler *transfer, selected) {
0809         if (!transfer) {
0810             continue;
0811         }
0812 
0813         // previous transfer was not of the same group, so after has to be reset as the group
0814         if (!group || (group != transfer->group())) {
0815             after = nullptr;
0816             group = transfer->group();
0817         }
0818         KGet::model()->moveTransfer(transfer, group, after);
0819         after = transfer;
0820     }
0821 }
0822 
0823 void MainWindow::slotPriorityBottom()
0824 {
0825     QList<TransferHandler *> selected = KGet::selectedTransfers();
0826     QList<TransferHandler *> groupTransfers;
0827     TransferHandler *after = nullptr;
0828     TransferGroupHandler *group = nullptr;
0829     foreach (TransferHandler *transfer, selected) {
0830         if (!transfer) {
0831             continue;
0832         }
0833 
0834         // previous transfer was not of the same group, so after has to be reset as the group
0835         if (!group || (group != transfer->group())) {
0836             group = transfer->group();
0837             groupTransfers = group->transfers();
0838             if (groupTransfers.isEmpty()) {
0839                 after = nullptr;
0840             } else {
0841                 after = groupTransfers.last();
0842             }
0843         }
0844 
0845         KGet::model()->moveTransfer(transfer, group, after);
0846         after = transfer;
0847     }
0848 }
0849 
0850 void MainWindow::slotPriorityUp()
0851 {
0852     QList<TransferHandler *> selected = KGet::selectedTransfers();
0853     QList<TransferHandler *> groupTransfers;
0854     TransferHandler *after = nullptr;
0855     int newIndex = -1;
0856     TransferGroupHandler *group = nullptr;
0857     foreach (TransferHandler *transfer, selected) {
0858         if (!transfer) {
0859             continue;
0860         }
0861 
0862         // previous transfer was not of the same group, so group has to be reset
0863         if (!group || (group != transfer->group())) {
0864             group = transfer->group();
0865             groupTransfers = group->transfers();
0866         }
0867 
0868         after = nullptr;
0869         if (!groupTransfers.isEmpty()) {
0870             int index = groupTransfers.indexOf(transfer);
0871 
0872             // do not move higher than the first place
0873             if (index > 0) {
0874                 // if only Transfers at the top are select do not change their order
0875                 if ((index - 1) != newIndex) {
0876                     newIndex = index - 1;
0877                     if (newIndex - 1 >= 0) {
0878                         after = groupTransfers[newIndex - 1];
0879                     }
0880 
0881                     // keep the list with the actual movements synchronized
0882                     groupTransfers.move(index, newIndex);
0883 
0884                     KGet::model()->moveTransfer(transfer, group, after);
0885                 } else {
0886                     newIndex = index;
0887                 }
0888             } else {
0889                 newIndex = 0;
0890             }
0891         }
0892     }
0893 }
0894 
0895 void MainWindow::slotPriorityDown()
0896 {
0897     QList<TransferHandler *> selected = KGet::selectedTransfers();
0898     QList<TransferHandler *> groupTransfers;
0899     int newIndex = -1;
0900     TransferGroupHandler *group = nullptr;
0901     for (int i = selected.count() - 1; i >= 0; --i) {
0902         TransferHandler *transfer = selected[i];
0903         if (!transfer) {
0904             continue;
0905         }
0906 
0907         // previous transfer was not of the same group, so group has to be reset
0908         if (!group || (group != transfer->group())) {
0909             group = transfer->group();
0910             groupTransfers = group->transfers();
0911         }
0912 
0913         if (!groupTransfers.isEmpty()) {
0914             int index = groupTransfers.indexOf(transfer);
0915 
0916             // do not move lower than the last place
0917             if ((index != -1) && (index + 1 < groupTransfers.count())) {
0918                 // if only Transfers at the top are select do not change their order
0919                 if ((index + 1) != newIndex) {
0920                     newIndex = index + 1;
0921                     TransferHandler *after = groupTransfers[newIndex];
0922 
0923                     // keep the list with the actual movements synchronized
0924                     groupTransfers.move(index, newIndex);
0925 
0926                     KGet::model()->moveTransfer(transfer, group, after);
0927                 } else {
0928                     newIndex = index;
0929                 }
0930             } else {
0931                 newIndex = index;
0932             }
0933         }
0934     }
0935 }
0936 
0937 void MainWindow::slotTransfersOpenDest()
0938 {
0939     QStringList openedDirs;
0940     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0941         QString directory = it->dest().adjusted(QUrl::RemoveFilename).toString();
0942         if (!openedDirs.contains(directory)) {
0943             new KRun(QUrl(directory), this);
0944             openedDirs.append(directory);
0945         }
0946     }
0947 }
0948 
0949 void MainWindow::slotTransfersOpenFile()
0950 {
0951     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0952         new KRun(it->dest(), this);
0953     }
0954 }
0955 
0956 void MainWindow::slotTransfersShowDetails()
0957 {
0958     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0959         m_viewsContainer->showTransferDetails(it);
0960     }
0961 }
0962 
0963 void MainWindow::slotTransfersCopySourceUrl()
0964 {
0965     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0966         QString sourceurl = it->source().url();
0967         QClipboard *cb = QApplication::clipboard();
0968         cb->setText(sourceurl, QClipboard::Selection);
0969         cb->setText(sourceurl, QClipboard::Clipboard);
0970     }
0971 }
0972 
0973 void MainWindow::slotDeleteFinished()
0974 {
0975     foreach (TransferHandler *it, KGet::finishedTransfers()) {
0976         m_viewsContainer->closeTransferDetails(it);
0977     }
0978     KGet::delTransfers(KGet::finishedTransfers());
0979 }
0980 
0981 void MainWindow::slotConfigureNotifications()
0982 {
0983     KNotifyConfigWidget::configure(this);
0984 }
0985 
0986 void MainWindow::slotSaveMyself()
0987 {
0988     // save last parameters ..
0989     Settings::setMainPosition(pos());
0990     // .. and write config to disk
0991     Settings::self()->save();
0992 }
0993 
0994 void MainWindow::slotNewToolbarConfig()
0995 {
0996     createGUI();
0997 }
0998 
0999 void MainWindow::slotNewConfig()
1000 {
1001     // Update here properties modified in the config dialog and not
1002     // parsed often by the code. When clicking Ok or Apply of
1003     // PreferencesDialog, this function is called.
1004 
1005     if (m_drop)
1006         m_drop->setDropTargetVisible(Settings::showDropTarget(), false);
1007 
1008     if (Settings::enableSystemTray() && !m_dock) {
1009         m_dock = new Tray(this);
1010     } else if (!Settings::enableSystemTray() && m_dock) {
1011         setVisible(true);
1012         delete m_dock;
1013         m_dock = nullptr;
1014     }
1015 
1016     slotKonquerorIntegration(Settings::konquerorIntegration());
1017     m_konquerorIntegration->setChecked(Settings::konquerorIntegration());
1018 
1019     if (clipboardTimer) {
1020         if (Settings::autoPaste())
1021             clipboardTimer->start(1000);
1022         else
1023             clipboardTimer->stop();
1024     }
1025     m_autoPasteAction->setChecked(Settings::autoPaste());
1026 
1027     /*if (Settings::webinterfaceEnabled() && !m_webinterface) {
1028         m_webinterface = new HttpServer(this);
1029     } else if (m_webinterface && !Settings::webinterfaceEnabled()) {
1030         delete m_webinterface;
1031         m_webinterface = nullptr;
1032     } else if (m_webinterface) {
1033         m_webinterface->settingsChanged();
1034     }*///TODO: Port to KF5
1035 
1036     if (Settings::speedLimit()) {
1037         KGet::setGlobalDownloadLimit(Settings::globalDownloadLimit());
1038         KGet::setGlobalUploadLimit(Settings::globalUploadLimit());
1039     } else {
1040         KGet::setGlobalDownloadLimit(0);
1041         KGet::setGlobalUploadLimit(0);
1042     }
1043 
1044     KGet::settingsChanged();
1045 }
1046 
1047 void MainWindow::slotToggleAutoPaste()
1048 {
1049     bool autoPaste = !Settings::autoPaste();
1050     Settings::setAutoPaste(autoPaste);
1051 
1052     if (autoPaste)
1053         clipboardTimer->start(1000);
1054     else
1055         clipboardTimer->stop();
1056     m_autoPasteAction->setChecked(autoPaste);
1057 }
1058 
1059 void MainWindow::slotCheckClipboard()
1060 {
1061     const QString clipData = QApplication::clipboard()->text(QClipboard::Clipboard).trimmed();
1062 
1063     if (clipData != lastClipboard) {
1064         lastClipboard = clipData;
1065         if (lastClipboard.isEmpty())
1066             return;
1067 
1068         const QUrl url = QUrl(lastClipboard);
1069         if (url.isValid() && !url.scheme().isEmpty() && !url.path().isEmpty() && !url.host().isEmpty() && !url.isLocalFile()) {
1070             bool add = false;
1071             const QString urlString = url.url();
1072 
1073             // check the combined whitelist and blacklist
1074             const QList<int> types = Settings::autoPasteTypes();
1075             const QList<int> syntaxes = Settings::autoPastePatternSyntaxes();
1076             const QStringList patterns = Settings::autoPastePatterns();
1077             const Qt::CaseSensitivity cs = (Settings::autoPasteCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive);
1078             for (int i = 0; i < types.count(); ++i) {
1079                 const QRegExp::PatternSyntax syntax = (syntaxes[i] == AutoPasteModel::Wildcard ? QRegExp::Wildcard : QRegExp::RegExp2);
1080                 QRegExp rx(patterns[i], cs, syntax);
1081                 if (rx.exactMatch(urlString)) {
1082                     add = (types[i] == AutoPasteModel::Include);
1083                     break;
1084                 }
1085             }
1086 
1087             if (add) {
1088                 KGet::addTransfer(url);
1089             }
1090         }
1091     }
1092 }
1093 
1094 void MainWindow::slotTrayKonquerorIntegration(bool enable)
1095 {
1096     slotKonquerorIntegration(enable);
1097     if (!enable && Settings::konquerorIntegration()) {
1098         KGet::showNotification(this,
1099                                "notification",
1100                                i18n("KGet has been temporarily disabled as download manager for Konqueror. "
1101                                     "If you want to disable it forever, go to Settings->Advanced and disable \"Use "
1102                                     "as download manager for Konqueror\"."),
1103                                "dialog-info");
1104         /*KMessageBox::information(this,
1105             i18n("KGet has been temporarily disabled as download manager for Konqueror. "
1106             "If you want to disable it forever, go to Settings->Advanced and disable \"Use "
1107             "as download manager for Konqueror\"."),
1108             i18n("Konqueror Integration disabled"),
1109             "KonquerorIntegrationDisabled");*/
1110     }
1111 }
1112 
1113 void MainWindow::slotKonquerorIntegration(bool konquerorIntegration)
1114 {
1115     KConfig cfgKonqueror("konquerorrc", KConfig::NoGlobals);
1116     cfgKonqueror.group("HTML Settings").writeEntry("DownloadManager", QString(konquerorIntegration ? "kget" : QString()));
1117     cfgKonqueror.sync();
1118 }
1119 
1120 void MainWindow::slotShowMenubar()
1121 {
1122     if (m_menubarAction->isChecked())
1123         menuBar()->show();
1124     else
1125         menuBar()->hide();
1126 }
1127 
1128 void MainWindow::setSystemTrayDownloading(bool running)
1129 {
1130     qCDebug(KGET_DEBUG);
1131 
1132     if (m_dock)
1133         m_dock->setDownloading(running);
1134 }
1135 
1136 void MainWindow::slotTransferHistory()
1137 {
1138     auto *history = new TransferHistory();
1139     history->exec();
1140 }
1141 
1142 void MainWindow::slotTransferGroupSettings()
1143 {
1144     qCDebug(KGET_DEBUG);
1145     QList<TransferGroupHandler *> list = KGet::selectedTransferGroups();
1146     foreach (TransferGroupHandler *group, list) {
1147         QPointer<GroupSettingsDialog> settings = new GroupSettingsDialog(this, group);
1148         settings->exec();
1149         delete settings;
1150     }
1151 }
1152 
1153 void MainWindow::slotTransferSettings()
1154 {
1155     qCDebug(KGET_DEBUG);
1156     QList<TransferHandler *> list = KGet::selectedTransfers();
1157     foreach (TransferHandler *transfer, list) {
1158         QPointer<TransferSettingsDialog> settings = new TransferSettingsDialog(this, transfer);
1159         settings->exec();
1160         delete settings;
1161     }
1162 }
1163 
1164 /** slots for link list **/
1165 void MainWindow::slotShowListLinks()
1166 {
1167     auto *link_view = new KGetLinkView(this);
1168     link_view->importUrl();
1169     link_view->show();
1170 }
1171 
1172 void MainWindow::slotImportUrl(const QString &url)
1173 {
1174     auto *link_view = new KGetLinkView(this);
1175     link_view->importUrl(url);
1176     link_view->show();
1177 }
1178 
1179 /** widget events **/
1180 void MainWindow::closeEvent(QCloseEvent *e)
1181 {
1182     // if the event comes from out the application (close event) we decide between close or hide
1183     // if the event comes from the application (system shutdown) we say goodbye
1184     if (e->spontaneous()) {
1185         e->ignore();
1186         if (!Settings::enableSystemTray())
1187             slotQuit();
1188         else
1189             hide();
1190     }
1191 }
1192 
1193 void MainWindow::hideEvent(QHideEvent *)
1194 {
1195     Settings::setShowMain(false);
1196 }
1197 
1198 void MainWindow::showEvent(QShowEvent *)
1199 {
1200     Settings::setShowMain(true);
1201 }
1202 
1203 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
1204 {
1205     event->setAccepted(event->mimeData()->hasUrls());
1206 }
1207 
1208 void MainWindow::dropEvent(QDropEvent *event)
1209 {
1210     QList<QUrl> list = event->mimeData()->urls();
1211 
1212     if (!list.isEmpty()) {
1213         if (list.count() == 1 && list.first().url().endsWith(QLatin1String(".kgt"))) {
1214 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1215             int msgBoxResult = KMessageBox::questionTwoActionsCancel(this,
1216 #else
1217             int msgBoxResult = KMessageBox::questionYesNoCancel(this,
1218 #endif
1219                                                                      i18n("The dropped file is a KGet Transfer List"),
1220                                                                      "KGet",
1221                                                                      KGuiItem(i18n("&Download"), QIcon::fromTheme("document-save")),
1222                                                                      KGuiItem(i18n("&Load transfer list"), QIcon::fromTheme("list-add")),
1223                                                                      KStandardGuiItem::cancel());
1224 
1225 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1226             if (msgBoxResult == KMessageBox::PrimaryAction) // Download
1227 #else
1228             if (msgBoxResult == KMessageBox::Yes) // Download
1229 #endif
1230                 NewTransferDialogHandler::showNewTransferDialog(list.first());
1231 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1232             if (msgBoxResult == KMessageBox::SecondaryAction) // Load
1233 #else
1234             if (msgBoxResult == KMessageBox::No) // Load
1235 #endif
1236                 KGet::load(list.first().url());
1237         } else {
1238             if (list.count() == 1)
1239                 NewTransferDialogHandler::showNewTransferDialog(list.first());
1240             else
1241                 NewTransferDialogHandler::showNewTransferDialog(list);
1242         }
1243     } else {
1244         NewTransferDialogHandler::showNewTransferDialog(QUrl());
1245     }
1246 }