File indexing completed on 2024-04-14 08:31:21

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 <KIO/JobUiDelegateFactory>
0045 #include <KIO/OpenUrlJob>
0046 #include <KIconDialog>
0047 #include <KLocalizedString>
0048 #include <KMessageBox>
0049 #include <KNotifyConfigWidget>
0050 #include <KSelectAction>
0051 #include <KStandardAction>
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     QAction *shutdownAction = downloadFinishedActions->addAction(i18n("Turn Off Computer"));
0366     shutdownAction->setData(KGet::Shutdown);
0367     connect(shutdownAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0368     downloadFinishedActions->addAction(shutdownAction);
0369 
0370     QAction *hibernateAction = downloadFinishedActions->addAction(i18n("Hibernate Computer"));
0371     hibernateAction->setData(KGet::Hibernate);
0372     connect(hibernateAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0373     downloadFinishedActions->addAction(hibernateAction);
0374 
0375     QAction *suspendAction = downloadFinishedActions->addAction(i18n("Suspend Computer"));
0376     suspendAction->setData(KGet::Suspend);
0377     connect(suspendAction, &QAction::triggered, this, &MainWindow::slotDownloadFinishedActions);
0378     downloadFinishedActions->addAction(suspendAction);
0379 
0380     if (Settings::afterFinishActionEnabled()) {
0381         downloadFinishedActions->setCurrentItem(Settings::afterFinishAction() + 1);
0382     } else {
0383         downloadFinishedActions->setCurrentItem(0);
0384     }
0385 }
0386 
0387 void MainWindow::slotDownloadFinishedActions()
0388 {
0389     auto *action = static_cast<QAction *>(QObject::sender());
0390     bool ok;
0391     const int type = action->data().toInt(&ok);
0392     if (ok) {
0393         Settings::self()->setAfterFinishAction(type);
0394     }
0395 
0396     // only after finish actions have a number assigned
0397     Settings::self()->setAfterFinishActionEnabled(ok);
0398     Settings::self()->save();
0399     slotNewConfig();
0400 }
0401 
0402 void MainWindow::init()
0403 {
0404     // Here we import the user's transfers.
0405     KGet::load(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/transfers.kgt"));
0406 
0407     if (Settings::enableSystemTray()) {
0408         m_dock = new Tray(this);
0409     }
0410 
0411     // enable dropping
0412     setAcceptDrops(true);
0413 
0414     // enable hide toolbar
0415     setStandardToolBarMenuEnabled(true);
0416 
0417     // session management stuff
0418     auto disableSessionManagement = [](QSessionManager &sm) {
0419         sm.setRestartHint(QSessionManager::RestartNever);
0420     };
0421     QObject::connect(qApp, &QGuiApplication::saveStateRequest, disableSessionManagement);
0422 
0423     // set auto-resume in kioslaverc (is there a cleaner way?)
0424     KConfig cfg("kioslaverc", KConfig::NoGlobals);
0425     cfg.group(QString()).writeEntry("AutoResume", true);
0426     cfg.sync();
0427 
0428     // DropTarget
0429     m_drop = new DropTarget(this);
0430 
0431     if (Settings::firstRun()) {
0432         if (KMessageBox::questionTwoActions(this,
0433                                             i18n("This is the first time you have run KGet.\n"
0434                                                  "Would you like to enable KGet as the download manager for Konqueror?"),
0435                                             i18n("Konqueror Integration"),
0436                                             KGuiItem(i18n("Enable")),
0437                                             KGuiItem(i18n("Do Not Enable")))
0438             == KMessageBox::PrimaryAction) {
0439             Settings::setKonquerorIntegration(true);
0440             m_konquerorIntegration->setChecked(Settings::konquerorIntegration());
0441             slotKonquerorIntegration(true);
0442         }
0443 
0444         m_drop->setDropTargetVisible(false);
0445 
0446         // reset the FirstRun config option
0447         Settings::setFirstRun(false);
0448     }
0449 
0450     if (Settings::showDropTarget() && !m_startWithoutAnimation)
0451         m_drop->setDropTargetVisible(true);
0452 
0453     // auto paste stuff
0454     lastClipboard = QApplication::clipboard()->text(QClipboard::Clipboard).trimmed();
0455     clipboardTimer = new QTimer(this);
0456     connect(clipboardTimer, &QTimer::timeout, this, &MainWindow::slotCheckClipboard);
0457     if (Settings::autoPaste())
0458         clipboardTimer->start(1000);
0459 
0460     /*if (Settings::webinterfaceEnabled())
0461         m_webinterface = new HttpServer(this);*///TODO: Port to KF5
0462 
0463     if (Settings::speedLimit()) {
0464         KGet::setGlobalDownloadLimit(Settings::globalDownloadLimit());
0465         KGet::setGlobalUploadLimit(Settings::globalUploadLimit());
0466     } else {
0467         KGet::setGlobalDownloadLimit(0);
0468         KGet::setGlobalUploadLimit(0);
0469     }
0470 
0471     connect(KGet::model(), &TransferTreeModel::transfersAddedEvent, this, &MainWindow::slotUpdateTitlePercent);
0472     connect(KGet::model(), &TransferTreeModel::transfersRemovedEvent, this, &MainWindow::slotUpdateTitlePercent);
0473     connect(KGet::model(), &TransferTreeModel::transfersChangedEvent, this, &MainWindow::slotTransfersChanged);
0474     connect(KGet::model(), &TransferTreeModel::groupsChangedEvent, this, &MainWindow::slotGroupsChanged);
0475 
0476 #ifdef DO_KGET_TEST
0477     if (m_doTesting) {
0478         // Unit testing
0479         TestKGet unitTest;
0480         QTest::qExec(&unitTest);
0481     }
0482 #endif
0483 }
0484 
0485 void MainWindow::slotToggleDropTarget()
0486 {
0487     m_drop->setDropTargetVisible(!m_drop->isVisible());
0488 }
0489 
0490 void MainWindow::slotNewTransfer()
0491 {
0492     NewTransferDialogHandler::showNewTransferDialog(QUrl());
0493 }
0494 
0495 void MainWindow::slotImportTransfers()
0496 {
0497     QString filename = QFileDialog::getOpenFileName(nullptr,
0498                                                     i18nc("@title:window", "Open File"),
0499                                                     QString(),
0500                                                     i18n("All Openable Files") + " (*.kgt *.metalink *.meta4 *.torrent)");
0501 
0502     if (filename.endsWith(QLatin1String(".kgt"))) {
0503         KGet::load(filename);
0504         return;
0505     }
0506 
0507     if (!filename.isEmpty())
0508         KGet::addTransfer(QUrl(filename));
0509 }
0510 
0511 void MainWindow::slotUpdateTitlePercent()
0512 {
0513     int percent = transfersPercent();
0514     if (percent != -1) {
0515         setPlainCaption(i18nc("window title including overall download progress in percent", "KGet - %1%", percent));
0516     } else {
0517         setPlainCaption(i18n("KGet"));
0518     }
0519 }
0520 
0521 void MainWindow::slotTransfersChanged(QMap<TransferHandler *, Transfer::ChangesFlags> transfers)
0522 {
0523     QMapIterator<TransferHandler *, Transfer::ChangesFlags> it(transfers);
0524 
0525     // QList<TransferHandler *> finishedTransfers;
0526     bool update = false;
0527 
0528     while (it.hasNext()) {
0529         it.next();
0530 
0531         // TransferHandler * transfer = it.key();
0532         Transfer::ChangesFlags transferFlags = it.value();
0533 
0534         if (transferFlags & Transfer::Tc_Percent || transferFlags & Transfer::Tc_Status) {
0535             update = true;
0536             break;
0537         }
0538 
0539         //         qCDebug(KGET_DEBUG) << it.key() << ": " << it.value() << endl;
0540     }
0541 
0542     if (update)
0543         slotUpdateTitlePercent();
0544 }
0545 
0546 void MainWindow::slotGroupsChanged(QMap<TransferGroupHandler *, TransferGroup::ChangesFlags> groups)
0547 {
0548     bool update = false;
0549     foreach (const TransferGroup::ChangesFlags &groupFlags, groups) {
0550         if (groupFlags & TransferGroup::Gc_Percent) {
0551             update = true;
0552             break;
0553         }
0554     }
0555     if (update)
0556         slotUpdateTitlePercent();
0557 }
0558 
0559 void MainWindow::slotQuit()
0560 {
0561     if (KGet::schedulerRunning()) {
0562         if (KMessageBox::warningTwoActions(this,
0563                                            i18n("Some transfers are still running.\n"
0564                                                 "Are you sure you want to close KGet?"),
0565                                            i18n("Confirm Quit"),
0566                                            KStandardGuiItem::quit(),
0567                                            KStandardGuiItem::cancel(),
0568                                            "ExitWithActiveTransfers")
0569             == KMessageBox::SecondaryAction)
0570             return;
0571     }
0572 
0573     Settings::self()->save();
0574     qApp->quit();
0575 }
0576 
0577 void MainWindow::slotPreferences()
0578 {
0579     // never reuse the preference dialog, to make sure its settings are always reloaded
0580     auto *dialog = new PreferencesDialog(this, Settings::self());
0581     dialog->setAttribute(Qt::WA_DeleteOnClose);
0582 
0583     // keep us informed when the user changes settings
0584     connect(dialog, &KConfigDialog::settingsChanged, this, &MainWindow::slotNewConfig);
0585 
0586     dialog->show();
0587 }
0588 
0589 void MainWindow::slotExportTransfers()
0590 {
0591     const QString filename = QFileDialog::getSaveFileName(this,
0592                                                           i18nc("@title:window", "Export Transfers"),
0593                                                           QString(),
0594                                                           i18n("KGet Transfer List") + " (*.kgt);;" + i18n("Text File") + " (*.txt)");
0595 
0596     if (!filename.isEmpty()) {
0597         const bool plain = !filename.endsWith(QLatin1String(".kgt"));
0598         KGet::save(filename, plain);
0599     }
0600 }
0601 
0602 void MainWindow::slotCreateMetalink()
0603 {
0604     auto *dialog = new MetalinkCreator(this);
0605     dialog->setAttribute(Qt::WA_DeleteOnClose);
0606     dialog->show();
0607 }
0608 
0609 void MainWindow::slotDeleteGroup()
0610 {
0611     QList<TransferGroupHandler *> groups = KGet::selectedTransferGroups();
0612     if (groups.count() != KGet::allTransferGroups().count()) {
0613         KGet::delGroups(groups);
0614     }
0615 }
0616 
0617 void MainWindow::slotRenameGroup()
0618 {
0619     bool ok = true;
0620     QString groupName;
0621 
0622     foreach (TransferGroupHandler *it, KGet::selectedTransferGroups()) {
0623         groupName = QInputDialog::getText(this, i18n("Enter Group Name"), i18n("Group name:"), QLineEdit::Normal, it->name(), &ok);
0624         if (ok)
0625             it->setName(groupName);
0626     }
0627 }
0628 
0629 void MainWindow::slotSetIconGroup()
0630 {
0631     KIconDialog dialog(this);
0632     QString iconName = dialog.getIcon();
0633     TransferTreeSelectionModel *selModel = KGet::selectionModel();
0634 
0635     QModelIndexList indexList = selModel->selectedRows();
0636 
0637     if (!iconName.isEmpty()) {
0638         foreach (TransferGroupHandler *group, KGet::selectedTransferGroups()) {
0639             group->setIconName(iconName);
0640         }
0641     }
0642     // Q_EMIT dataChanged(indexList.first(),indexList.last());
0643 }
0644 
0645 void MainWindow::slotStartDownload()
0646 {
0647     if (KGet::selectedTransfers().size() == 0 && KGet::selectedTransferGroups().size() == 0) {
0648         slotStartAllDownload();
0649     } else {
0650         slotStartSelectedDownload();
0651     }
0652 }
0653 
0654 void MainWindow::slotStartAllDownload()
0655 {
0656     KGet::setSchedulerRunning(true);
0657 }
0658 
0659 void MainWindow::slotStartSelectedDownload()
0660 {
0661     KGet::setSuspendScheduler(true);
0662     foreach (TransferHandler *transfer, KGet::selectedTransfers()) {
0663         transfer->start();
0664     }
0665     foreach (TransferGroupHandler *group, KGet::selectedTransferGroups()) {
0666         group->start();
0667     }
0668     KGet::setSuspendScheduler(false);
0669 }
0670 
0671 void MainWindow::slotStopDownload()
0672 {
0673     if (KGet::selectedTransfers().size() == 0 && KGet::selectedTransferGroups().size() == 0) {
0674         slotStopAllDownload();
0675     } else {
0676         slotStopSelectedDownload();
0677     }
0678 }
0679 
0680 void MainWindow::slotStopAllDownload()
0681 {
0682     KGet::setSchedulerRunning(false);
0683 
0684     // This line ensures that each transfer is stopped. In the handler class
0685     // the policy of the transfer will be correctly set to None
0686     foreach (TransferHandler *it, KGet::allTransfers())
0687         it->stop();
0688 }
0689 
0690 void MainWindow::slotStopSelectedDownload()
0691 {
0692     KGet::setSuspendScheduler(true);
0693     foreach (TransferHandler *transfer, KGet::selectedTransfers()) {
0694         transfer->stop();
0695     }
0696     foreach (TransferGroupHandler *group, KGet::selectedTransferGroups()) {
0697         group->stop();
0698     }
0699     KGet::setSuspendScheduler(false);
0700 }
0701 
0702 void MainWindow::slotDeleteSelected()
0703 {
0704     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0705         if (it->status() != Job::Finished && it->status() != Job::FinishedKeepAlive) {
0706             if (KMessageBox::warningTwoActions(this,
0707                                                i18np("Are you sure you want to delete the selected transfer?",
0708                                                      "Are you sure you want to delete the selected transfers?",
0709                                                      KGet::selectedTransfers().count()),
0710                                                i18n("Confirm transfer delete"),
0711                                                KStandardGuiItem::remove(),
0712                                                KStandardGuiItem::cancel())
0713                 == KMessageBox::SecondaryAction) {
0714                 return;
0715             }
0716             break;
0717         }
0718     }
0719 
0720     const QList<TransferHandler *> selectedTransfers = KGet::selectedTransfers();
0721     if (!selectedTransfers.isEmpty()) {
0722         foreach (TransferHandler *it, selectedTransfers) {
0723             m_viewsContainer->closeTransferDetails(it); // TODO make it take QList?
0724         }
0725         KGet::delTransfers(KGet::selectedTransfers());
0726     } else {
0727         // no transfers selected, delete groups if any are selected
0728         slotDeleteGroup();
0729     }
0730 }
0731 
0732 void MainWindow::slotDeleteSelectedIncludingFiles()
0733 {
0734     const QList<TransferHandler *> selectedTransfers = KGet::selectedTransfers();
0735 
0736     if (!selectedTransfers.isEmpty()) {
0737         if (KMessageBox::warningTwoActions(this,
0738                                            i18np("Are you sure you want to delete the selected transfer including files?",
0739                                                  "Are you sure you want to delete the selected transfers including files?",
0740                                                  selectedTransfers.count()),
0741                                            i18n("Confirm transfer delete"),
0742                                            KStandardGuiItem::remove(),
0743                                            KStandardGuiItem::cancel())
0744             == KMessageBox::SecondaryAction) {
0745             return;
0746         }
0747         foreach (TransferHandler *it, selectedTransfers) {
0748             m_viewsContainer->closeTransferDetails(it); // TODO make it take QList?
0749         }
0750         KGet::delTransfers(KGet::selectedTransfers(), KGet::DeleteFiles);
0751     } else {
0752         // no transfers selected, delete groups if any are selected
0753         slotDeleteGroup();
0754     }
0755 }
0756 
0757 void MainWindow::slotRedownloadSelected()
0758 {
0759     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0760         KGet::redownloadTransfer(it);
0761     }
0762 }
0763 
0764 void MainWindow::slotPriorityTop()
0765 {
0766     QList<TransferHandler *> selected = KGet::selectedTransfers();
0767     TransferHandler *after = nullptr;
0768     TransferGroupHandler *group = nullptr;
0769     foreach (TransferHandler *transfer, selected) {
0770         if (!transfer) {
0771             continue;
0772         }
0773 
0774         // previous transfer was not of the same group, so after has to be reset as the group
0775         if (!group || (group != transfer->group())) {
0776             after = nullptr;
0777             group = transfer->group();
0778         }
0779         KGet::model()->moveTransfer(transfer, group, after);
0780         after = transfer;
0781     }
0782 }
0783 
0784 void MainWindow::slotPriorityBottom()
0785 {
0786     QList<TransferHandler *> selected = KGet::selectedTransfers();
0787     QList<TransferHandler *> groupTransfers;
0788     TransferHandler *after = nullptr;
0789     TransferGroupHandler *group = nullptr;
0790     foreach (TransferHandler *transfer, selected) {
0791         if (!transfer) {
0792             continue;
0793         }
0794 
0795         // previous transfer was not of the same group, so after has to be reset as the group
0796         if (!group || (group != transfer->group())) {
0797             group = transfer->group();
0798             groupTransfers = group->transfers();
0799             if (groupTransfers.isEmpty()) {
0800                 after = nullptr;
0801             } else {
0802                 after = groupTransfers.last();
0803             }
0804         }
0805 
0806         KGet::model()->moveTransfer(transfer, group, after);
0807         after = transfer;
0808     }
0809 }
0810 
0811 void MainWindow::slotPriorityUp()
0812 {
0813     QList<TransferHandler *> selected = KGet::selectedTransfers();
0814     QList<TransferHandler *> groupTransfers;
0815     TransferHandler *after = nullptr;
0816     int newIndex = -1;
0817     TransferGroupHandler *group = nullptr;
0818     foreach (TransferHandler *transfer, selected) {
0819         if (!transfer) {
0820             continue;
0821         }
0822 
0823         // previous transfer was not of the same group, so group has to be reset
0824         if (!group || (group != transfer->group())) {
0825             group = transfer->group();
0826             groupTransfers = group->transfers();
0827         }
0828 
0829         after = nullptr;
0830         if (!groupTransfers.isEmpty()) {
0831             int index = groupTransfers.indexOf(transfer);
0832 
0833             // do not move higher than the first place
0834             if (index > 0) {
0835                 // if only Transfers at the top are select do not change their order
0836                 if ((index - 1) != newIndex) {
0837                     newIndex = index - 1;
0838                     if (newIndex - 1 >= 0) {
0839                         after = groupTransfers[newIndex - 1];
0840                     }
0841 
0842                     // keep the list with the actual movements synchronized
0843                     groupTransfers.move(index, newIndex);
0844 
0845                     KGet::model()->moveTransfer(transfer, group, after);
0846                 } else {
0847                     newIndex = index;
0848                 }
0849             } else {
0850                 newIndex = 0;
0851             }
0852         }
0853     }
0854 }
0855 
0856 void MainWindow::slotPriorityDown()
0857 {
0858     QList<TransferHandler *> selected = KGet::selectedTransfers();
0859     QList<TransferHandler *> groupTransfers;
0860     int newIndex = -1;
0861     TransferGroupHandler *group = nullptr;
0862     for (int i = selected.count() - 1; i >= 0; --i) {
0863         TransferHandler *transfer = selected[i];
0864         if (!transfer) {
0865             continue;
0866         }
0867 
0868         // previous transfer was not of the same group, so group has to be reset
0869         if (!group || (group != transfer->group())) {
0870             group = transfer->group();
0871             groupTransfers = group->transfers();
0872         }
0873 
0874         if (!groupTransfers.isEmpty()) {
0875             int index = groupTransfers.indexOf(transfer);
0876 
0877             // do not move lower than the last place
0878             if ((index != -1) && (index + 1 < groupTransfers.count())) {
0879                 // if only Transfers at the top are select do not change their order
0880                 if ((index + 1) != newIndex) {
0881                     newIndex = index + 1;
0882                     TransferHandler *after = groupTransfers[newIndex];
0883 
0884                     // keep the list with the actual movements synchronized
0885                     groupTransfers.move(index, newIndex);
0886 
0887                     KGet::model()->moveTransfer(transfer, group, after);
0888                 } else {
0889                     newIndex = index;
0890                 }
0891             } else {
0892                 newIndex = index;
0893             }
0894         }
0895     }
0896 }
0897 
0898 void MainWindow::slotTransfersOpenDest()
0899 {
0900     QStringList openedDirs;
0901     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0902         QString directory = it->dest().adjusted(QUrl::RemoveFilename).toString();
0903         if (!openedDirs.contains(directory)) {
0904             auto job = new KIO::OpenUrlJob(QUrl(directory), this);
0905             job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
0906             job->start();
0907             openedDirs.append(directory);
0908         }
0909     }
0910 }
0911 
0912 void MainWindow::slotTransfersOpenFile()
0913 {
0914     const auto tranfers = KGet::selectedTransfers();
0915     for (TransferHandler *it : tranfers) {
0916         auto job = new KIO::OpenUrlJob(it->dest(), this);
0917         job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
0918         job->start();
0919     }
0920 }
0921 
0922 void MainWindow::slotTransfersShowDetails()
0923 {
0924     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0925         m_viewsContainer->showTransferDetails(it);
0926     }
0927 }
0928 
0929 void MainWindow::slotTransfersCopySourceUrl()
0930 {
0931     foreach (TransferHandler *it, KGet::selectedTransfers()) {
0932         QString sourceurl = it->source().url();
0933         QClipboard *cb = QApplication::clipboard();
0934         cb->setText(sourceurl, QClipboard::Selection);
0935         cb->setText(sourceurl, QClipboard::Clipboard);
0936     }
0937 }
0938 
0939 void MainWindow::slotDeleteFinished()
0940 {
0941     foreach (TransferHandler *it, KGet::finishedTransfers()) {
0942         m_viewsContainer->closeTransferDetails(it);
0943     }
0944     KGet::delTransfers(KGet::finishedTransfers());
0945 }
0946 
0947 void MainWindow::slotConfigureNotifications()
0948 {
0949     KNotifyConfigWidget::configure(this);
0950 }
0951 
0952 void MainWindow::slotSaveMyself()
0953 {
0954     // save last parameters ..
0955     Settings::setMainPosition(pos());
0956     // .. and write config to disk
0957     Settings::self()->save();
0958 }
0959 
0960 void MainWindow::slotNewToolbarConfig()
0961 {
0962     createGUI();
0963 }
0964 
0965 void MainWindow::slotNewConfig()
0966 {
0967     // Update here properties modified in the config dialog and not
0968     // parsed often by the code. When clicking Ok or Apply of
0969     // PreferencesDialog, this function is called.
0970 
0971     if (m_drop)
0972         m_drop->setDropTargetVisible(Settings::showDropTarget(), false);
0973 
0974     if (Settings::enableSystemTray() && !m_dock) {
0975         m_dock = new Tray(this);
0976     } else if (!Settings::enableSystemTray() && m_dock) {
0977         setVisible(true);
0978         delete m_dock;
0979         m_dock = nullptr;
0980     }
0981 
0982     slotKonquerorIntegration(Settings::konquerorIntegration());
0983     m_konquerorIntegration->setChecked(Settings::konquerorIntegration());
0984 
0985     if (clipboardTimer) {
0986         if (Settings::autoPaste())
0987             clipboardTimer->start(1000);
0988         else
0989             clipboardTimer->stop();
0990     }
0991     m_autoPasteAction->setChecked(Settings::autoPaste());
0992 
0993     /*if (Settings::webinterfaceEnabled() && !m_webinterface) {
0994         m_webinterface = new HttpServer(this);
0995     } else if (m_webinterface && !Settings::webinterfaceEnabled()) {
0996         delete m_webinterface;
0997         m_webinterface = nullptr;
0998     } else if (m_webinterface) {
0999         m_webinterface->settingsChanged();
1000     }*///TODO: Port to KF5
1001 
1002     if (Settings::speedLimit()) {
1003         KGet::setGlobalDownloadLimit(Settings::globalDownloadLimit());
1004         KGet::setGlobalUploadLimit(Settings::globalUploadLimit());
1005     } else {
1006         KGet::setGlobalDownloadLimit(0);
1007         KGet::setGlobalUploadLimit(0);
1008     }
1009 
1010     KGet::settingsChanged();
1011 }
1012 
1013 void MainWindow::slotToggleAutoPaste()
1014 {
1015     bool autoPaste = !Settings::autoPaste();
1016     Settings::setAutoPaste(autoPaste);
1017 
1018     if (autoPaste)
1019         clipboardTimer->start(1000);
1020     else
1021         clipboardTimer->stop();
1022     m_autoPasteAction->setChecked(autoPaste);
1023 }
1024 
1025 void MainWindow::slotCheckClipboard()
1026 {
1027     const QString clipData = QApplication::clipboard()->text(QClipboard::Clipboard).trimmed();
1028 
1029     if (clipData != lastClipboard) {
1030         lastClipboard = clipData;
1031         if (lastClipboard.isEmpty())
1032             return;
1033 
1034         const QUrl url = QUrl(lastClipboard);
1035         if (url.isValid() && !url.scheme().isEmpty() && !url.path().isEmpty() && !url.host().isEmpty() && !url.isLocalFile()) {
1036             bool add = false;
1037             const QString urlString = url.url();
1038 
1039             // check the combined whitelist and blacklist
1040             const QList<int> types = Settings::autoPasteTypes();
1041             const QList<int> syntaxes = Settings::autoPastePatternSyntaxes();
1042             const QStringList patterns = Settings::autoPastePatterns();
1043             const Qt::CaseSensitivity cs = (Settings::autoPasteCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive);
1044             for (int i = 0; i < types.count(); ++i) {
1045                 QRegularExpression regex;
1046                 if (syntaxes[i] == AutoPasteModel::Wildcard) {
1047                     regex = QRegularExpression::fromWildcard(patterns[i]);
1048                 } else {
1049                     regex = QRegularExpression(patterns[i]);
1050                 }
1051                 if (!Settings::autoPasteCaseSensitive()) {
1052                     regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
1053                 }
1054                 QRegularExpression rx(QRegularExpression::anchoredPattern(patterns[i]));
1055                 if (rx.match(urlString).hasMatch()) {
1056                     add = (types[i] == AutoPasteModel::Include);
1057                     break;
1058                 }
1059             }
1060 
1061             if (add) {
1062                 KGet::addTransfer(url);
1063             }
1064         }
1065     }
1066 }
1067 
1068 void MainWindow::slotTrayKonquerorIntegration(bool enable)
1069 {
1070     slotKonquerorIntegration(enable);
1071     if (!enable && Settings::konquerorIntegration()) {
1072         KGet::showNotification("notification",
1073                                i18n("KGet has been temporarily disabled as download manager for Konqueror. "
1074                                     "If you want to disable it forever, go to Settings->Advanced and disable \"Use "
1075                                     "as download manager for Konqueror\"."),
1076                                "dialog-info");
1077         /*KMessageBox::information(this,
1078             i18n("KGet has been temporarily disabled as download manager for Konqueror. "
1079             "If you want to disable it forever, go to Settings->Advanced and disable \"Use "
1080             "as download manager for Konqueror\"."),
1081             i18n("Konqueror Integration disabled"),
1082             "KonquerorIntegrationDisabled");*/
1083     }
1084 }
1085 
1086 void MainWindow::slotKonquerorIntegration(bool konquerorIntegration)
1087 {
1088     KConfig cfgKonqueror("konquerorrc", KConfig::NoGlobals);
1089     cfgKonqueror.group("HTML Settings").writeEntry("DownloadManager", QString(konquerorIntegration ? "kget" : QString()));
1090     cfgKonqueror.sync();
1091 }
1092 
1093 void MainWindow::slotShowMenubar()
1094 {
1095     if (m_menubarAction->isChecked())
1096         menuBar()->show();
1097     else
1098         menuBar()->hide();
1099 }
1100 
1101 void MainWindow::setSystemTrayDownloading(bool running)
1102 {
1103     qCDebug(KGET_DEBUG);
1104 
1105     if (m_dock)
1106         m_dock->setDownloading(running);
1107 }
1108 
1109 void MainWindow::slotTransferHistory()
1110 {
1111     auto *history = new TransferHistory();
1112     history->exec();
1113 }
1114 
1115 void MainWindow::slotTransferGroupSettings()
1116 {
1117     qCDebug(KGET_DEBUG);
1118     QList<TransferGroupHandler *> list = KGet::selectedTransferGroups();
1119     foreach (TransferGroupHandler *group, list) {
1120         QPointer<GroupSettingsDialog> settings = new GroupSettingsDialog(this, group);
1121         settings->exec();
1122         delete settings;
1123     }
1124 }
1125 
1126 void MainWindow::slotTransferSettings()
1127 {
1128     qCDebug(KGET_DEBUG);
1129     QList<TransferHandler *> list = KGet::selectedTransfers();
1130     foreach (TransferHandler *transfer, list) {
1131         QPointer<TransferSettingsDialog> settings = new TransferSettingsDialog(this, transfer);
1132         settings->exec();
1133         delete settings;
1134     }
1135 }
1136 
1137 /** slots for link list **/
1138 void MainWindow::slotShowListLinks()
1139 {
1140     auto *link_view = new KGetLinkView(this);
1141     link_view->importUrl();
1142     link_view->show();
1143 }
1144 
1145 void MainWindow::slotImportUrl(const QString &url)
1146 {
1147     auto *link_view = new KGetLinkView(this);
1148     link_view->importUrl(url);
1149     link_view->show();
1150 }
1151 
1152 /** widget events **/
1153 void MainWindow::closeEvent(QCloseEvent *e)
1154 {
1155     // if the event comes from out the application (close event) we decide between close or hide
1156     // if the event comes from the application (system shutdown) we say goodbye
1157     if (e->spontaneous()) {
1158         e->ignore();
1159         if (!Settings::enableSystemTray())
1160             slotQuit();
1161         else
1162             hide();
1163     }
1164 }
1165 
1166 void MainWindow::hideEvent(QHideEvent *)
1167 {
1168     Settings::setShowMain(false);
1169 }
1170 
1171 void MainWindow::showEvent(QShowEvent *)
1172 {
1173     Settings::setShowMain(true);
1174 }
1175 
1176 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
1177 {
1178     event->setAccepted(event->mimeData()->hasUrls());
1179 }
1180 
1181 void MainWindow::dropEvent(QDropEvent *event)
1182 {
1183     QList<QUrl> list = event->mimeData()->urls();
1184 
1185     if (!list.isEmpty()) {
1186         if (list.count() == 1 && list.first().url().endsWith(QLatin1String(".kgt"))) {
1187             int msgBoxResult = KMessageBox::questionTwoActionsCancel(this,
1188                                                                      i18n("The dropped file is a KGet Transfer List"),
1189                                                                      "KGet",
1190                                                                      KGuiItem(i18n("&Download"), QIcon::fromTheme("document-save")),
1191                                                                      KGuiItem(i18n("&Load transfer list"), QIcon::fromTheme("list-add")),
1192                                                                      KStandardGuiItem::cancel());
1193 
1194             if (msgBoxResult == KMessageBox::PrimaryAction) // Download
1195                 NewTransferDialogHandler::showNewTransferDialog(list.first());
1196             if (msgBoxResult == KMessageBox::SecondaryAction) // Load
1197                 KGet::load(list.first().url());
1198         } else {
1199             if (list.count() == 1)
1200                 NewTransferDialogHandler::showNewTransferDialog(list.first());
1201             else
1202                 NewTransferDialogHandler::showNewTransferDialog(list);
1203         }
1204     } else {
1205         NewTransferDialogHandler::showNewTransferDialog(QUrl());
1206     }
1207 }
1208 
1209 #include "moc_mainwindow.cpp"