File indexing completed on 2024-12-01 07:38:57

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2009 by Fabian Henze <flyser42 AT gmx DOT de>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 */
0010 #include "ui/tray.h"
0011 #include "mainwindow.h"
0012 #include "ui/newtransferdialog.h"
0013 
0014 #include "kget_debug.h"
0015 #include <QDebug>
0016 
0017 #include <KAboutData>
0018 #include <KActionCollection>
0019 #include <KLocalizedString>
0020 
0021 #include <QClipboard>
0022 #include <QMenu>
0023 
0024 /** class Tray
0025  * Reimplementation of the KStatusNotifierItem class
0026  */
0027 Tray::Tray(MainWindow *parent)
0028     : KStatusNotifierItem(parent)
0029 {
0030     // set up the context menu
0031     QMenu *cm = contextMenu();
0032     cm->addAction(parent->actionCollection()->action("new_download"));
0033     cm->addAction(parent->actionCollection()->action("import_links"));
0034     cm->addSeparator();
0035     cm->addAction(parent->actionCollection()->action("start_all_download"));
0036     cm->addAction(parent->actionCollection()->action("stop_all_download"));
0037     cm->addSeparator();
0038     cm->addAction(parent->actionCollection()->action("konqueror_integration"));
0039     cm->addAction(parent->actionCollection()->action("options_configure"));
0040 
0041     // Set up basic tray parameters
0042     setCategory(ApplicationStatus);
0043     setIconByName("kget");
0044     setTitle(i18n("KGet"));
0045     setContextMenu(cm);
0046     setAssociatedWindow(parent->windowHandle());
0047     setToolTipIconByName("kget");
0048     setToolTipTitle(i18n("Download Manager"));
0049     // Not of much use atm, but maybe we want to set this later?
0050     // setToolTipSubTitle("[..]");
0051 
0052     // filter middle mouse clicks to ask scheduler to paste URL
0053     connect(this, &Tray::secondaryActivateRequested, this, &Tray::slotActivated);
0054 }
0055 
0056 // filter middle mouse clicks to ask scheduler to paste URL
0057 void Tray::slotActivated()
0058 {
0059     // Here we paste the transfer
0060     QString newtransfer = QApplication::clipboard()->text();
0061     newtransfer = newtransfer.trimmed();
0062 
0063     if (!newtransfer.isEmpty())
0064         NewTransferDialogHandler::showNewTransferDialog(QUrl(newtransfer));
0065 }
0066 
0067 // display a play icon when downloading and
0068 // switch between Active or Passive state
0069 void Tray::setDownloading(bool downloading)
0070 {
0071     qCDebug(KGET_DEBUG) << "Tray::setDownloading";
0072 
0073     if (downloading) {
0074         if (status() == KStatusNotifierItem::Active)
0075             return;
0076         setStatus(KStatusNotifierItem::Active);
0077         setOverlayIconByName("media-playback-start");
0078     } else {
0079         if (status() == KStatusNotifierItem::Passive)
0080             return;
0081         setStatus(KStatusNotifierItem::Passive);
0082         setOverlayIconByName(QString());
0083     }
0084 }
0085 
0086 bool Tray::isDownloading()
0087 {
0088     // KStatusNotifierItem::NeedsAttention is not handled here,
0089     // as we do not use it.
0090     return (status() == KStatusNotifierItem::Active);
0091 }
0092 
0093 #include "moc_tray.cpp"