diff --git a/ui/tray.cpp b/ui/tray.cpp index 01db7dc6..b4bf8b0e 100644 --- a/ui/tray.cpp +++ b/ui/tray.cpp @@ -1,98 +1,112 @@ /* This file is part of the KDE project Copyright (C) 2009 by Fabian Henze This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #include "ui/tray.h" #include "mainwindow.h" #include "ui/newtransferdialog.h" #include "kget_debug.h" #include #include #include #include #include #include #include /** class Tray * Reimplementation of the KStatusNotifierItem class */ Tray::Tray(MainWindow * parent) : KStatusNotifierItem(parent) { // set up the context menu QMenu * cm = contextMenu(); cm->addAction( parent->actionCollection()->action("new_download") ); cm->addAction( parent->actionCollection()->action("import_links") ); cm->addSeparator(); cm->addAction( parent->actionCollection()->action("start_all_download") ); cm->addAction( parent->actionCollection()->action("stop_all_download") ); cm->addSeparator(); cm->addAction( parent->actionCollection()->action("konqueror_integration") ); cm->addAction( parent->actionCollection()->action("options_configure") ); // Set up basic tray parameters setCategory(ApplicationStatus); setIconByName("kget"); setTitle(i18n("KGet")); setContextMenu(cm); setAssociatedWidget(parent); setToolTipIconByName("kget"); setToolTipTitle(i18n("Download Manager")); // Not of much use atm, but maybe we want to set this later? // setToolTipSubTitle("[..]"); // filter middle mouse clicks to ask scheduler to paste URL connect(this, &Tray::secondaryActivateRequested, this, &Tray::slotActivated); + + // show/hide the main window if requested + // KSystemTrayItem should handle this, but that apparenly doesn't work on Wayland (bug 389663) + connect(this, &Tray::activateRequested, this, &Tray::slotRestore); } // filter middle mouse clicks to ask scheduler to paste URL void Tray::slotActivated() { // Here we paste the transfer QString newtransfer = QApplication::clipboard()->text(); newtransfer = newtransfer.trimmed(); if(!newtransfer.isEmpty()) NewTransferDialogHandler::showNewTransferDialog(QUrl(newtransfer)); } +// show/hide the main window if requested +// KSystemTrayItem should handle this, but that apparenly doesn't work on Wayland (bug 389663) +void Tray::slotRestore(bool active) +{ + if (active) + associatedWidget()->show(); + else + associatedWidget()->hide(); +} + // display a play icon when downloading and // switch between Active or Passive state void Tray::setDownloading( bool downloading ) { qCDebug(KGET_DEBUG) << "Tray::setDownloading"; if (downloading) { if (status() == KStatusNotifierItem::Active) return; setStatus(KStatusNotifierItem::Active); setOverlayIconByName("media-playback-start"); } else { if (status() == KStatusNotifierItem::Passive) return; setStatus(KStatusNotifierItem::Passive); setOverlayIconByName(QString()); } } bool Tray::isDownloading() { // KStatusNotifierItem::NeedsAttention is not handled here, // as we do not use it. return (status() == KStatusNotifierItem::Active); } diff --git a/ui/tray.h b/ui/tray.h index 304a6bd0..27cfab08 100644 --- a/ui/tray.h +++ b/ui/tray.h @@ -1,40 +1,41 @@ /* This file is part of the KDE project Copyright (C) 2009 by Fabian Henze This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #ifndef TRAY_H #define TRAY_H #include class MainWindow; class KGet; /** * This class implements the main tray icon for kget. It has a popup * from which the user can open a new transfer, configure kget, * minimize/restore or quit the app (default behavior). * * @short KGet's system tray icon. **/ class Tray : public KStatusNotifierItem { Q_OBJECT public: Tray( MainWindow * parent ); void setDownloading(bool downloading); bool isDownloading(); private slots: void slotActivated(); + void slotRestore(bool active); }; #endif