Skip to content

Commit

Permalink
Tray icon menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Aug 12, 2022
1 parent df211cf commit b0e4ef6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
38 changes: 31 additions & 7 deletions qpp/prefetch/Source/Interface/tray_icon.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include <QMenu>
#include <QAction>
#include <QLabel>
#include <QWidgetAction>
#include <string>
#include <iostream>

#include "..\Global\global.h"
#include "..\Output\stdout.h"
#include "..\Input\stdin.h"
#include "..\Setting\setting.h"

QSystemTrayIcon *TrayIcon::systemTrayIcon = NULL;

Expand All @@ -12,6 +17,20 @@ void TrayIcon::init()

QMenu *qMenu = new QMenu();

// Get instance name
auto instanceName = Setting::getString("Instance", "Name", Setting::setting);

// Text may not show when mouse hover in newer operating system
// https://bugreports.qt.io/browse/QTBUG-18821
systemTrayIcon->setToolTip(instanceName);

// Show instance name, a seperator with text
// https://stackoverflow.com/questions/37976696/why-qmenus-separator-doesnt-show-text
QLabel *instanceNameLabel = new QLabel(instanceName);
QWidgetAction *instanceNameSeparator = new QWidgetAction(systemTrayIcon);
instanceNameSeparator->setDefaultWidget(instanceNameLabel);
qMenu->addAction(instanceNameSeparator);

QAction *pauseAction = new QAction("Pause", qMenu);
connect(pauseAction, SIGNAL(triggered()), this, SLOT(action_pause()));
qMenu->addAction(pauseAction);
Expand All @@ -29,15 +48,20 @@ void TrayIcon::start()
TrayIcon::systemTrayIcon->show();
}

namespace ConsoleCommandFunction
{
// Actually is not stdin, but behaves very similarly
void sendTextToStdIn(QString text)
{
Global::inputLoopThreadAddress->receiveText(text);
}
}

void TrayIcon::action_pause()
{
*StdOut::consoleOutput << "Click pause"
<< endl;
StdOut::consoleOutput->flush();
ConsoleCommandFunction::sendTextToStdIn("pause");
}
void TrayIcon::action_resume()
{
*StdOut::consoleOutput << "Click resume"
<< endl;
StdOut::consoleOutput->flush();
ConsoleCommandFunction::sendTextToStdIn("resume");
}
5 changes: 4 additions & 1 deletion qpp/prefetch/prefetch.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ Firefox=explorer Firefox.lnk
MaxThreadCount=0
RescanInterval=0
PrefetchInterval=90
ReadThreadPriority=LowestPriority
ReadThreadPriority=LowestPriority

[Instance]
Name=Firefox

0 comments on commit b0e4ef6

Please sign in to comment.