mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 23:47:21 +00:00
rewrite tray
This commit is contained in:
parent
bf6d7cd53b
commit
10499691b3
@ -65,8 +65,8 @@ TODO (wish list)
|
||||
----------------
|
||||
|
||||
* plasmoid helper integration
|
||||
* more tray actions
|
||||
* include security notes / project architecture
|
||||
* remove suid from helper (polkit integration or run through sudo)
|
||||
* security notes / project architecture
|
||||
* autotests
|
||||
|
||||
Links
|
||||
|
@ -307,6 +307,12 @@ th.sub {
|
||||
<td><code>true</code> and shows settings window</td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>QStringList VerboseInformation()</td>
|
||||
<td>returns information in format <code>[isNetctlAutoActive, ProfileList, ActiveProfile, isProfileEnabled/autoIsProfileEnabled]</code></td>
|
||||
<td>no</td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><a href="#links" class="anchor" name="links"></a>External links</h2>
|
||||
|
@ -117,6 +117,132 @@ void MainWindow::showSettingsWindow()
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::enableProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[enableProfileSlot]";
|
||||
if (debug) qDebug() << "[MainWindow]" << "[enableProfileSlot]" << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Enable"),
|
||||
args, true, debug);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileEnabled"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->enableProfile(profile);
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::restartProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[restartProfileSlot]";
|
||||
if (debug) qDebug() << "[MainWindow]" << "[restartProfileSlot]" << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Restart"),
|
||||
args, true, debug)[0].toBool();
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->restartProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::startProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[startProfileSlot]";
|
||||
if (debug) qDebug() << "[MainWindow]" << "[startProfileSlot]" << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Start"),
|
||||
args, true, debug);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->startProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::switchToProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[switchToProfileSlot]";
|
||||
if (debug) qDebug() << "[MainWindow]" << "[switchToProfileSlot]" << ":" << "Profile" << profile;
|
||||
|
||||
bool netctlAutoStatus = false;
|
||||
if (useHelper)
|
||||
netctlAutoStatus = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
|
||||
QList<QVariant>(), true, debug)[0].toBool();
|
||||
else
|
||||
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
|
||||
|
||||
bool current;
|
||||
if (netctlAutoStatus) {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("autoStart"),
|
||||
args, true, debug);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("autoIsProfileActive"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->autoStartProfile(profile);
|
||||
current = netctlCommand->autoIsProfileActive(profile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("SwitchTo"),
|
||||
args, true, debug);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->switchToProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showApi()
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[showApi]";
|
||||
@ -400,23 +526,9 @@ void MainWindow::mainTabEnableProfile()
|
||||
return;
|
||||
|
||||
ui->tabWidget->setDisabled(true);
|
||||
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty();
|
||||
bool current;
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Enable"),
|
||||
args, true, debug);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileEnabled"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->enableProfile(profile);
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
}
|
||||
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty();
|
||||
bool current = enableProfileSlot(profile);
|
||||
if (current != previous)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
@ -462,21 +574,7 @@ void MainWindow::mainTabRestartProfile()
|
||||
|
||||
ui->tabWidget->setDisabled(true);
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Restart"),
|
||||
args, true, debug)[0].toBool();
|
||||
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->restartProfile(profile);
|
||||
status = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
bool status = restartProfileSlot(profile);
|
||||
if (status)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
@ -495,23 +593,9 @@ void MainWindow::mainTabStartProfile()
|
||||
return;
|
||||
|
||||
ui->tabWidget->setDisabled(true);
|
||||
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty();
|
||||
bool current;
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Start"),
|
||||
args, true, debug);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->startProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty();
|
||||
bool current = startProfileSlot(profile);
|
||||
if (current != previous)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
|
@ -116,7 +116,7 @@ MainWindow::~MainWindow()
|
||||
}
|
||||
|
||||
|
||||
QString MainWindow::printInformation()
|
||||
QStringList MainWindow::printInformation()
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[printInformation]";
|
||||
|
||||
@ -139,8 +139,9 @@ QString MainWindow::printInformation()
|
||||
status = netctlCommand->getProfileStatus(profile);
|
||||
}
|
||||
}
|
||||
QString output = QString("%1: %2\n").arg(QApplication::translate("MainWindow", "Profile")).arg(profile);
|
||||
output += QString("%1: %2").arg(QApplication::translate("MainWindow", "Status")).arg(status);
|
||||
QStringList output;
|
||||
output.append(profile);
|
||||
output.append(status);
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -159,6 +160,62 @@ QStringList MainWindow::printSettings()
|
||||
}
|
||||
|
||||
|
||||
QStringList MainWindow::printTrayInformation()
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[printTrayInformation]";
|
||||
|
||||
QStringList information;
|
||||
QString current;
|
||||
bool enabled = false;
|
||||
bool netctlAutoStatus = false;
|
||||
QList<netctlProfileInfo> profiles;
|
||||
if (useHelper) {
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("ActiveProfile"),
|
||||
QList<QVariant>(), true, debug)[0].toString();
|
||||
netctlAutoStatus = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
|
||||
QList<QVariant>(), true, debug)[0].toBool();
|
||||
profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("ProfileList"),
|
||||
QList<QVariant>(), true, debug), debug);
|
||||
QList<QVariant> args;
|
||||
args.append(current);
|
||||
if (netctlAutoStatus)
|
||||
enabled = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("autoIsProfileEnabled"),
|
||||
args, true, debug)[0].toBool();
|
||||
else
|
||||
enabled = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileEnabled"),
|
||||
args, true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
|
||||
if (netctlAutoStatus) {
|
||||
current = netctlCommand->autoGetActiveProfile();
|
||||
enabled = netctlCommand->autoIsProfileEnabled(current);
|
||||
profiles = netctlCommand->getProfileListFromNetctlAuto();
|
||||
}
|
||||
else {
|
||||
current = netctlCommand->getActiveProfile();
|
||||
enabled = netctlCommand->isProfileEnabled(current);
|
||||
profiles = netctlCommand->getProfileList();
|
||||
}
|
||||
}
|
||||
|
||||
information.append(QString::number(netctlAutoStatus));
|
||||
QStringList profileList;
|
||||
for (int i=0; i<profiles.count(); i++)
|
||||
profileList.append(profiles[i].name);
|
||||
information.append(profileList.join(QChar('|')));
|
||||
information.append(current);
|
||||
information.append(QString::number(enabled));
|
||||
|
||||
return information;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::isHelperActive()
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[isHelperActive]";
|
||||
|
@ -56,8 +56,9 @@ public:
|
||||
const QMap<QString, QVariant> args = QMap<QString, QVariant>(),
|
||||
QTranslator *appTranslator = 0);
|
||||
~MainWindow();
|
||||
QString printInformation();
|
||||
QStringList printInformation();
|
||||
QStringList printSettings();
|
||||
QStringList printTrayInformation();
|
||||
bool isHelperActive();
|
||||
bool isHelperServiceActive();
|
||||
|
||||
@ -71,6 +72,11 @@ public slots:
|
||||
void showMainWindow();
|
||||
void showNetctlAutoWindow();
|
||||
void showSettingsWindow();
|
||||
// trayicon control slots
|
||||
bool enableProfileSlot(const QString profile);
|
||||
bool startProfileSlot(const QString profile);
|
||||
bool switchToProfileSlot(const QString profile);
|
||||
bool restartProfileSlot(const QString profile);
|
||||
// open docs
|
||||
void showApi();
|
||||
void showLibrary();
|
||||
|
@ -176,7 +176,7 @@ void NetctlAutoWindow::netctlAutoUpdateTable()
|
||||
DBUS_HELPER_INTERFACE, QString("isNetctlAutoEnabled"),
|
||||
QList<QVariant>(), true, debug)[0].toBool();
|
||||
running = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isNetctlAutoRunning"),
|
||||
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
|
||||
QList<QVariant>(), true, debug)[0].toBool();
|
||||
}
|
||||
else {
|
||||
|
@ -45,7 +45,7 @@ bool NetctlGuiAdaptor::Close()
|
||||
}
|
||||
|
||||
|
||||
QString NetctlGuiAdaptor::Information()
|
||||
QStringList NetctlGuiAdaptor::Information()
|
||||
{
|
||||
return mainWindow->printInformation();
|
||||
}
|
||||
@ -102,3 +102,9 @@ bool NetctlGuiAdaptor::ShowSettings()
|
||||
mainWindow->showSettingsWindow();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlGuiAdaptor::VerboseInformation()
|
||||
{
|
||||
return mainWindow->printTrayInformation();
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
public slots:
|
||||
void ApiDocs();
|
||||
bool Close();
|
||||
QString Information();
|
||||
QStringList Information();
|
||||
void LibraryDocs();
|
||||
bool Restore();
|
||||
void SecurityDocs();
|
||||
@ -45,6 +45,7 @@ public slots:
|
||||
bool ShowMain();
|
||||
bool ShowNetctlAuto();
|
||||
bool ShowSettings();
|
||||
QStringList VerboseInformation();
|
||||
|
||||
private:
|
||||
MainWindow *mainWindow;
|
||||
|
@ -39,10 +39,14 @@ TrayIcon::~TrayIcon()
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[~TrayIcon]";
|
||||
|
||||
setContextMenu(0);
|
||||
delete exit;
|
||||
delete showMainWindow;
|
||||
delete showNetctlAutoWindow;
|
||||
delete showStatus;
|
||||
startProfileMenu->clear();
|
||||
switchToProfileMenu->clear();
|
||||
menuActions->clear();
|
||||
delete startProfileMenu;
|
||||
delete switchToProfileMenu;
|
||||
delete menuActions;
|
||||
for (int i=0; i<contextMenu.keys().count(); i++)
|
||||
delete contextMenu[contextMenu.keys()[i]];
|
||||
}
|
||||
|
||||
|
||||
@ -52,7 +56,9 @@ int TrayIcon::showInformation()
|
||||
|
||||
if (supportsMessages()) {
|
||||
QString title = QApplication::translate("TrayIcon", "netctl status");
|
||||
QString message = mainWindow->printInformation();
|
||||
QStringList info = mainWindow->printInformation();
|
||||
QString message = QString("%1: %2\n").arg(QApplication::translate("TrayIcon", "Profile")).arg(info[0]);
|
||||
message += QString("%1: %2").arg(QApplication::translate("TrayIcon", "Status")).arg(info[1]);
|
||||
showMessage(title, message, QSystemTrayIcon::Information);
|
||||
}
|
||||
else
|
||||
@ -66,12 +72,137 @@ int TrayIcon::showInformationInWindow()
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[showInformationInWindow]";
|
||||
|
||||
QString title = QApplication::translate("TrayIcon", "netctl status");
|
||||
QString message = mainWindow->printInformation();
|
||||
QStringList info = mainWindow->printInformation();
|
||||
QString message = QString("%1: %2\n").arg(QApplication::translate("TrayIcon", "Profile")).arg(info[0]);
|
||||
message += QString("%1: %2").arg(QApplication::translate("TrayIcon", "Status")).arg(info[1]);
|
||||
|
||||
return QMessageBox::information(0, title, message);
|
||||
}
|
||||
|
||||
|
||||
void TrayIcon::updateMenu()
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[showInformationInWindow]";
|
||||
|
||||
QStringList info = mainWindow->printTrayInformation();
|
||||
bool netctlAutoStatus = info[0].toInt();
|
||||
QStringList profiles = info[1].split(QChar('|'));
|
||||
QString current = info[2];
|
||||
bool enabled = info[3].toInt();
|
||||
|
||||
if (current.isEmpty()) {
|
||||
contextMenu[QString("title")]->setIcon(QIcon(QString(":network-offline-64x64")));
|
||||
contextMenu[QString("title")]->setText(QApplication::translate("TrayIcon", "(inactive)"));
|
||||
}
|
||||
else {
|
||||
contextMenu[QString("title")]->setIcon(QIcon(QString(":network-idle-64x64")));
|
||||
QString status;
|
||||
if (netctlAutoStatus)
|
||||
status = QApplication::translate("TrayIcon", "(netctl-auto)");
|
||||
else if (enabled)
|
||||
status = QApplication::translate("TrayIcon", "(enabled)");
|
||||
else
|
||||
status = QApplication::translate("TrayIcon", "(static)");
|
||||
contextMenu[QString("title")]->setText(current + QString(" ") + status);
|
||||
}
|
||||
|
||||
if (netctlAutoStatus) {
|
||||
contextMenu[QString("start")]->setVisible(false);
|
||||
contextMenu[QString("stop")]->setVisible(false);
|
||||
contextMenu[QString("switch")]->setVisible(true);
|
||||
contextMenu[QString("restart")]->setVisible(false);
|
||||
contextMenu[QString("enable")]->setVisible(false);
|
||||
|
||||
switchToProfileMenu->clear();
|
||||
for (int i=0; i<profiles.count(); i++) {
|
||||
QAction *profile = new QAction(profiles[i], this);
|
||||
switchToProfileMenu->addAction(profile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
contextMenu[QString("start")]->setVisible(true);
|
||||
contextMenu[QString("stop")]->setVisible(!current.isEmpty());
|
||||
contextMenu[QString("switch")]->setVisible(false);
|
||||
contextMenu[QString("restart")]->setVisible(!current.isEmpty());
|
||||
contextMenu[QString("enable")]->setVisible(!current.isEmpty());
|
||||
if (!current.isEmpty()) {
|
||||
contextMenu[QString("start")]->setText(QApplication::translate("TrayIcon", "Start another profile"));
|
||||
contextMenu[QString("stop")]->setText(QApplication::translate("TrayIcon", "Stop %1").arg(current));
|
||||
contextMenu[QString("restart")]->setText(QApplication::translate("TrayIcon", "Restart %1").arg(current));
|
||||
if (enabled)
|
||||
contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Disable %1").arg(current));
|
||||
else
|
||||
contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Enable %1").arg(current));
|
||||
}
|
||||
else
|
||||
contextMenu[QString("start")]->setText(QApplication::translate("TrayIcon", "Start profile"));
|
||||
startProfileMenu->clear();
|
||||
for (int i=0; i<profiles.count(); i++) {
|
||||
QAction *profile = new QAction(profiles[i], this);
|
||||
startProfileMenu->addAction(profile);
|
||||
}
|
||||
}
|
||||
|
||||
if (mainWindow->isHidden())
|
||||
contextMenu[QString("gui")]->setText(QApplication::translate("TrayIcon", "Show"));
|
||||
else
|
||||
contextMenu[QString("gui")]->setText(QApplication::translate("TrayIcon", "Hide"));
|
||||
}
|
||||
|
||||
|
||||
void TrayIcon::createActions()
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[createActions]";
|
||||
|
||||
menuActions = new QMenu();
|
||||
|
||||
contextMenu[QString("title")] = new QAction(QIcon(":icon"), QApplication::translate("TrayIcon", "Status"), this);
|
||||
menuActions->addAction(contextMenu[QString("title")]);
|
||||
|
||||
menuActions->addSeparator();
|
||||
|
||||
contextMenu[QString("start")] = new QAction(QIcon::fromTheme("system-run"), QApplication::translate("TrayIcon", "Start profile"), this);
|
||||
startProfileMenu = new QMenu();
|
||||
contextMenu[QString("start")]->setMenu(startProfileMenu);
|
||||
connect(startProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(startProfileSlot(QAction *)));
|
||||
menuActions->addAction(contextMenu[QString("start")]);
|
||||
|
||||
contextMenu[QString("stop")] = new QAction(QIcon::fromTheme("process-stop"), QApplication::translate("TrayIcon", "Stop profile"), this);
|
||||
connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot()));
|
||||
menuActions->addAction(contextMenu[QString("stop")]);
|
||||
|
||||
contextMenu[QString("switch")] = new QAction(QIcon::fromTheme("system-run"), QApplication::translate("TrayIcon", "Switch to profile"), this);
|
||||
switchToProfileMenu = new QMenu();
|
||||
contextMenu[QString("switch")]->setMenu(switchToProfileMenu);
|
||||
connect(switchToProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(switchToProfileSlot(QAction *)));
|
||||
menuActions->addAction(contextMenu[QString("switch")]);
|
||||
|
||||
contextMenu[QString("restart")] = new QAction(QIcon::fromTheme("stock-refresh"), QApplication::translate("TrayIcon", "Restart profile"), this);
|
||||
connect(contextMenu[QString("restart")], SIGNAL(triggered(bool)), this, SLOT(restartProfileSlot()));
|
||||
menuActions->addAction(contextMenu[QString("restart")]);
|
||||
|
||||
contextMenu[QString("enable")] = new QAction(QApplication::translate("TrayIcon", "Enable profile"), this);
|
||||
connect(contextMenu[QString("enable")], SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot()));
|
||||
menuActions->addAction(contextMenu[QString("enable")]);
|
||||
|
||||
menuActions->addSeparator();
|
||||
|
||||
contextMenu[QString("gui")] = new QAction(QApplication::translate("TrayIcon", "Show"), this);
|
||||
connect(contextMenu[QString("gui")], SIGNAL(triggered(bool)), mainWindow, SLOT(showMainWindow()));
|
||||
menuActions->addAction(contextMenu[QString("gui")]);
|
||||
|
||||
contextMenu[QString("auto")] = new QAction(QApplication::translate("TrayIcon", "Show netctl-auto"), this);
|
||||
connect(contextMenu[QString("auto")], SIGNAL(triggered(bool)), mainWindow, SLOT(showNetctlAutoWindow()));
|
||||
menuActions->addAction(contextMenu[QString("auto")]);
|
||||
|
||||
menuActions->addSeparator();
|
||||
|
||||
contextMenu[QString("quit")] = new QAction(QApplication::translate("TrayIcon", "Quit"), this);
|
||||
connect(contextMenu[QString("quit")], SIGNAL(triggered(bool)), mainWindow, SLOT(closeMainWindow()));
|
||||
menuActions->addAction(contextMenu[QString("quit")]);
|
||||
}
|
||||
|
||||
|
||||
void TrayIcon::init()
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[init]";
|
||||
@ -79,23 +210,8 @@ void TrayIcon::init()
|
||||
setIcon(QIcon(":icon"));
|
||||
setToolTip(QString("netctl-gui"));
|
||||
|
||||
exit = new QAction(QIcon::fromTheme("exit"), QApplication::translate("TrayIcon", "Quit"), this);
|
||||
connect(exit, SIGNAL(triggered(bool)), mainWindow, SLOT(closeMainWindow()));
|
||||
showMainWindow = new QAction(QApplication::translate("TrayIcon", "Show"), this);
|
||||
connect(showMainWindow, SIGNAL(triggered(bool)), mainWindow, SLOT(showMainWindow()));
|
||||
showNetctlAutoWindow = new QAction(QApplication::translate("TrayIcon", "Show netctl-auto"), this);
|
||||
connect(showNetctlAutoWindow, SIGNAL(triggered(bool)),mainWindow, SLOT(showNetctlAutoWindow()));
|
||||
showStatus = new QAction(QIcon(":icon"), QApplication::translate("TrayIcon", "Status"), this);
|
||||
connect(showStatus, SIGNAL(triggered(bool)), this, SLOT(showInformation()));
|
||||
|
||||
QMenu *menu = new QMenu();
|
||||
menu->addAction(showStatus);
|
||||
menu->addSeparator();
|
||||
menu->addAction(showMainWindow);
|
||||
menu->addAction(showNetctlAutoWindow);
|
||||
menu->addSeparator();
|
||||
menu->addAction(exit);
|
||||
setContextMenu(menu);
|
||||
createActions();
|
||||
setContextMenu(menuActions);
|
||||
|
||||
connect(this, SIGNAL(messageClicked()), this, SLOT(showInformationInWindow()));
|
||||
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||
@ -116,12 +232,59 @@ void TrayIcon::itemActivated(const QSystemTrayIcon::ActivationReason reason)
|
||||
mainWindow->showMainWindow();
|
||||
break;
|
||||
case QSystemTrayIcon::Context:
|
||||
if (mainWindow->isHidden())
|
||||
showMainWindow->setText(QApplication::translate("TrayIcon", "Show"));
|
||||
else
|
||||
showMainWindow->setText(QApplication::translate("TrayIcon", "Hide"));
|
||||
updateMenu();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool TrayIcon::enableProfileSlot()
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[enableProfileSlot]";
|
||||
|
||||
QString profile = mainWindow->printInformation()[0];
|
||||
|
||||
return mainWindow->enableProfileSlot(profile);
|
||||
}
|
||||
|
||||
|
||||
bool TrayIcon::restartProfileSlot()
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[restartProfileSlot]";
|
||||
|
||||
QString profile = mainWindow->printInformation()[0];
|
||||
|
||||
return mainWindow->restartProfileSlot(profile);
|
||||
}
|
||||
|
||||
|
||||
bool TrayIcon::startProfileSlot(QAction *action)
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[startProfileSlot]";
|
||||
|
||||
QString profile = action->text().remove(QChar('&'));
|
||||
|
||||
return mainWindow->switchToProfileSlot(profile);
|
||||
}
|
||||
|
||||
|
||||
bool TrayIcon::stopProfileSlot()
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[stopProfileSlot]";
|
||||
|
||||
QString profile = mainWindow->printInformation()[0];
|
||||
|
||||
return mainWindow->startProfileSlot(profile);
|
||||
}
|
||||
|
||||
|
||||
bool TrayIcon::switchToProfileSlot(QAction *action)
|
||||
{
|
||||
if (debug) qDebug() << "[TrayIcon]" << "[switchToProfileSlot]";
|
||||
|
||||
QString profile = action->text().remove(QChar('&'));
|
||||
|
||||
return mainWindow->switchToProfileSlot(profile);
|
||||
}
|
||||
|
@ -37,19 +37,26 @@ public:
|
||||
public slots:
|
||||
int showInformation();
|
||||
int showInformationInWindow();
|
||||
void updateMenu();
|
||||
|
||||
private slots:
|
||||
void itemActivated(const QSystemTrayIcon::ActivationReason reason);
|
||||
bool enableProfileSlot();
|
||||
bool restartProfileSlot();
|
||||
bool startProfileSlot(QAction *action);
|
||||
bool stopProfileSlot();
|
||||
bool switchToProfileSlot(QAction *action);
|
||||
|
||||
private:
|
||||
bool debug;
|
||||
MainWindow *mainWindow;
|
||||
// contextual actions
|
||||
QMenu *menu;
|
||||
QAction *exit;
|
||||
QAction *showMainWindow;
|
||||
QAction *showNetctlAutoWindow;
|
||||
QAction *showStatus;
|
||||
QMenu *menuActions;
|
||||
QMenu *startProfileMenu;
|
||||
QMenu *switchToProfileMenu;
|
||||
QMap<QString, QAction*> contextMenu;
|
||||
// functions
|
||||
void createActions();
|
||||
void init();
|
||||
};
|
||||
|
||||
|
@ -6,5 +6,7 @@
|
||||
<!-- icons -->
|
||||
<file>icon.png</file>
|
||||
<file>wifi.png</file>
|
||||
<file>network-idle-64x64.png</file>
|
||||
<file>network-offline-64x64.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Loading…
Reference in New Issue
Block a user