summaryrefslogtreecommitdiff
path: root/SystrayIcon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SystrayIcon.cpp')
-rw-r--r--SystrayIcon.cpp90
1 files changed, 75 insertions, 15 deletions
diff --git a/SystrayIcon.cpp b/SystrayIcon.cpp
index b4fef7d..4a1c8f1 100644
--- a/SystrayIcon.cpp
+++ b/SystrayIcon.cpp
@@ -16,26 +16,30 @@ SystrayIcon::SystrayIcon()
//setup the systray icon
haveListenerInfo = false;
havePluginLoaderInfo = false;
- sysTrayIcon = new QSystemTrayIcon();
systrayMenu = new QMenu();
actionMenuAbout = new QAction(this);
actionMenuQuit = new QAction(this);
actionOptions = new QAction(this);
//actionTransfer = new QAction(this);
copyMenu = new QMenu();
- sysTrayIcon->setContextMenu(systrayMenu);
- sysTrayIcon->setToolTip("Ultracopier");
+ //to prevent init bug
+ stateListener=NotListening;
+ statePluginLoader=Uncaught;
+
+ setContextMenu(systrayMenu);
+ setToolTip("Ultracopier");
#ifdef Q_OS_WIN32
- sysTrayIcon->setIcon(QIcon(":/systray_Uncaught_Windows.png"));
+ setIcon(QIcon(":/systray_Uncaught_Windows.png"));
#else
- sysTrayIcon->setIcon(QIcon(":/systray_Uncaught_Unix.png"));
+ setIcon(QIcon(":/systray_Uncaught_Unix.png"));
#endif
- sysTrayIcon->show();
+ show();
//connect the action
+ connect(&timerCheckSetTooltip, SIGNAL(timeout()), this, SLOT(checkSetTooltip()));
connect(actionMenuQuit, SIGNAL(triggered()), this, SIGNAL(quit()));
connect(actionMenuAbout, SIGNAL(triggered()), this, SIGNAL(showHelp()));
connect(actionOptions, SIGNAL(triggered()), this, SIGNAL(showOptions()));
- connect(sysTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(CatchAction(QSystemTrayIcon::ActivationReason)));
+ connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(CatchAction(QSystemTrayIcon::ActivationReason)));
connect(plugins, SIGNAL(pluginListingIsfinish()), this, SLOT(reloadEngineList()));
//display the icon
updateCurrentTheme();
@@ -49,6 +53,13 @@ SystrayIcon::SystrayIcon()
systrayMenu->insertSeparator(actionOptions);
retranslateTheUI();
updateSystrayIcon();
+
+ timerCheckSetTooltip.setSingleShot(true);
+ timerCheckSetTooltip.start(1000);
+
+ //impossible with Qt on systray
+ /// \note important for drag and drop, \see dropEvent()
+ systrayMenu->setAcceptDrops(true);
}
/// \brief Hide and destroy the icon in the systray
@@ -59,7 +70,17 @@ SystrayIcon::~SystrayIcon()
delete actionOptions;
delete systrayMenu;
delete copyMenu;
- delete sysTrayIcon;
+}
+
+void SystrayIcon::checkSetTooltip()
+{
+ if(isSystemTrayAvailable())
+ {
+ setToolTip("Ultracopier");
+ updateSystrayIcon();
+ }
+ else
+ timerCheckSetTooltip.start();
}
void SystrayIcon::listenerReady(const ListeningState &state,const bool &havePlugin,const bool &someAreInWaitOfReply)
@@ -92,14 +113,14 @@ void SystrayIcon::showTryCatchMessageWithNoListener()
/// \brief To show a message linked to the systray icon
void SystrayIcon::showSystrayMessage(const QString& text)
{
- sysTrayIcon->showMessage(tr("Information"),text,QSystemTrayIcon::Information,0);
+ showMessage(tr("Information"),text,QSystemTrayIcon::Information,0);
}
/// \brief To update the systray icon
void SystrayIcon::updateSystrayIcon()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start, haveListenerInfo %1, havePluginLoaderInfo: %2").arg(haveListenerInfo).arg(havePluginLoaderInfo));
- QString toolTip;
+ QString toolTip="???";
QString icon;
if(!haveListenerInfo || !havePluginLoaderInfo)
{
@@ -112,8 +133,6 @@ void SystrayIcon::updateSystrayIcon()
CatchState statePluginLoader=this->statePluginLoader;
if(!haveListener)
stateListener=NotListening;
- if(!havePluginLoader)
- statePluginLoader=Caught;
if((stateListener==NotListening && statePluginLoader==Uncaught) || (stateListener==SemiListening && statePluginLoader==Semiuncaught) || (stateListener==FullListening && statePluginLoader==Caught))
{
if(stateListener==NotListening)
@@ -180,10 +199,48 @@ void SystrayIcon::updateSystrayIcon()
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"icon: systray_"+icon+"_Unix.png");
#endif
}
- sysTrayIcon->setIcon(theNewSystrayIcon);
- sysTrayIcon->setToolTip("Ultracopier - "+toolTip);
+ setIcon(theNewSystrayIcon);
+ setToolTip("Ultracopier - "+toolTip);
}
+/* drag event processing (impossible with Qt on systray)
+
+need setAcceptDrops(true); into the constructor
+need implementation to accept the drop:
+void dragEnterEvent(QDragEnterEvent* event);
+void dragMoveEvent(QDragMoveEvent* event);
+void dragLeaveEvent(QDragLeaveEvent* event);
+*/
+void SystrayIcon::dropEvent(QDropEvent *event)
+{
+ const QMimeData* mimeData = event->mimeData();
+ if(mimeData->hasUrls())
+ {
+ //impossible with Qt on systray
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"mimeData->urls().size()"+QString::number(mimeData->urls().size()));
+ emit urlDropped(mimeData->urls());
+ event->acceptProposedAction();
+ }
+}
+
+void SystrayIcon::dragEnterEvent(QDragEnterEvent* event)
+{
+ // if some actions should not be usable, like move, this code must be adopted
+ event->acceptProposedAction();
+}
+
+void SystrayIcon::dragMoveEvent(QDragMoveEvent* event)
+{
+ // if some actions should not be usable, like move, this code must be adopted
+ event->acceptProposedAction();
+}
+
+void SystrayIcon::dragLeaveEvent(QDragLeaveEvent* event)
+{
+ event->accept();
+}
+
+
/// \brief To update the current themes
void SystrayIcon::updateCurrentTheme()
{
@@ -231,12 +288,15 @@ void SystrayIcon::CatchAction(QSystemTrayIcon::ActivationReason reason)
if(reason==QSystemTrayIcon::DoubleClick || reason==QSystemTrayIcon::Trigger)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"Double click on system tray icon");
- if(stateListener!=NotListening || statePluginLoader!=Uncaught)
+ if(stateListener!=NotListening)
emit tryUncatchCopy();
else
{
if(!haveListener)
+ {
showTryCatchMessageWithNoListener();
+ return;
+ }
emit tryCatchCopy();
}
}