From 725ca9791ec516f1bb0c5a37ec17fbedd888d928 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 13 Oct 2016 13:10:34 -0400 Subject: Another large update to lumina-fm: Have all file operations performed in the background, and show up within a new system tray icon *if* the operation lasts longer than 1 second (automatic cleanup for short ops). --- src-qt5/desktop-utils/lumina-fm/TrayUI.cpp | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src-qt5/desktop-utils/lumina-fm/TrayUI.cpp (limited to 'src-qt5/desktop-utils/lumina-fm/TrayUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-fm/TrayUI.cpp b/src-qt5/desktop-utils/lumina-fm/TrayUI.cpp new file mode 100644 index 00000000..8e796c68 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-fm/TrayUI.cpp @@ -0,0 +1,86 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "TrayUI.h" + +#include +#include + +TrayUI::TrayUI(QObject *parent) : QSystemTrayIcon(parent){ + this->setContextMenu( new QMenu() ); + this->setIcon(LXDG::findIcon("Insight-FileManager","")); +} + +TrayUI::~TrayUI(){ + this->contextMenu()->deleteLater(); +} + +void TrayUI::StartOperation( FILEOP op, QStringList oldF, QStringList newF){ + createOP(op, oldF, newF); + QTimer::singleShot(1000, this, SLOT(checkJobs())); +} + +void TrayUI::createOP( FILEOP type, QStringList oldF, QStringList newF){ + OPWidget *OP = new OPWidget(); + if(type==MOVE){ OP->setupOperation("move", oldF, newF); } + else if(type==COPY){ OP->setupOperation("copy", oldF, newF); } + else if(type==DELETE){ OP->setupOperation("delete",oldF, QStringList()); } + else{ OP->deleteLater(); return; } //invalid type of operation + OP->setWhatsThis( QUuid::createUuid().toString() ); + this->contextMenu()->addAction(OP->widgetAction()); + OPS << OP; + connect(OP, SIGNAL(starting(QString)), this, SLOT(OperationStarted(QString)) ); + connect(OP, SIGNAL(finished(QString)), this, SLOT(OperationFinished(QString)) ); + connect(OP, SIGNAL(closed(QString)), this, SLOT(OperationClosed(QString)) ); + QTimer::singleShot(0, OP, SLOT(startOperation()) ); +} + +//Operation Widget Responses +void TrayUI::OperationClosed(QString ID){ + for(int i=0; iwhatsThis()==ID){ + //qDebug() << "Removing OPWidget:" << ID; + //this->contextMenu()->removeAction(OPS[i]->widgetAction()); + OPS.takeAt(i)->deleteLater(); + break; + } + } + QTimer::singleShot(1000, this, SLOT(checkJobs()) ); +} + +void TrayUI::OperationStarted(QString ID){ + for(int i=0; iwhatsThis()==ID){ + //NOTHING FOR NOW - ENABLE POPUPS LATER (if desired - they can get annoying for short operations) + } + } +} + +void TrayUI::OperationFinished(QString ID){ + //qDebug() << "Op Finished:" << ID; + for(int i=0; iwhatsThis()!=ID){ continue; } + //qDebug() << " - found widget"; + bool err = OPS[i]->hasErrors(); + //qDebug() << " -- Errors:" << err << "Duration:" << OPS[i]->duration(); + //Assemble the notification (if more than 1 second to perform operation) + if(OPS[i]->duration()>1){ + this->showMessage( tr("Finished"), err ? tr("Errors during operation. Click to view details") : tr("No Errors"), err ? QSystemTrayIcon::Warning : QSystemTrayIcon::Information); + } + //Close the widget if no errors + if(!err){ OperationClosed(ID); } + break; + } +} + +void TrayUI::checkJobs(){ + if(OPS.isEmpty()){ + emit JobsFinished(); + this->hide(); + }else{ + this->show(); + } +} -- cgit