8 #include <QSharedMemory>
10 #include <QMessageBox>
21 "<blockquote><code>sudo systemctl start ckb-daemon</code></blockquote>" +
22 QObject::tr(
"Enable it for every boot:") +
23 "<blockquote><code>sudo systemctl enable ckb-daemon</code></blockquote>";
26 "<blockquote><code>sudo launchctl start com.ckb.daemon.plist</code></blockquote>" +
27 QObject::tr(
"Enable it for every boot:") +
28 "<blockquote><code>sudo launchctl enable /Library/LaunchDaemons/com.ckb.daemon.plist</code></blockquote>";
33 #ifdef USE_LIBAPPINDICATOR
35 void quitIndicator(GtkMenu* menu, gpointer data) {
41 void restoreIndicator(GtkMenu* menu, gpointer data) {
47 #endif // USE_LIBAPPINDICATOR
66 #ifdef USE_LIBAPPINDICATOR
67 QString desktop = std::getenv(
"XDG_CURRENT_DESKTOP");
68 unityDesktop = (desktop.toLower() ==
"unity");
73 indicatorMenu = gtk_menu_new();
74 indicatorMenuRestoreItem = gtk_menu_item_new_with_label(
"Restore");
75 indicatorMenuQuitItem = gtk_menu_item_new_with_label(
"Quit ckb");
77 gtk_menu_shell_append(GTK_MENU_SHELL(indicatorMenu), indicatorMenuRestoreItem);
78 gtk_menu_shell_append(GTK_MENU_SHELL(indicatorMenu), indicatorMenuQuitItem);
80 g_signal_connect(indicatorMenuQuitItem,
"activate",
81 G_CALLBACK(quitIndicator),
this);
82 g_signal_connect(indicatorMenuRestoreItem,
"activate",
83 G_CALLBACK(restoreIndicator),
this);
85 gtk_widget_show(indicatorMenuRestoreItem);
86 gtk_widget_show(indicatorMenuQuitItem);
88 indicator = app_indicator_new(
"ckb",
"indicator-messages", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
90 app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
91 app_indicator_set_menu(indicator, GTK_MENU(indicatorMenu));
92 app_indicator_set_icon(indicator,
"ckb");
94 #endif // USE_LIBAPPINDICATOR
99 trayIcon =
new QSystemTrayIcon(QIcon(
":/img/ckb-logo.png"),
this);
101 connect(
trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(
iconClicked(QSystemTrayIcon::ActivationReason)));
107 QMenuBar* menuBar =
new QMenuBar(
this);
109 this->menuBar()->addMenu(
"ckb")->addAction(
closeAction);
112 new QShortcut(QKeySequence(
"Ctrl+Q"),
this, SLOT(
quitApp()));
118 connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
this, SLOT(
stateChange(Qt::ApplicationState)));
120 connect(qApp, SIGNAL(aboutToQuit()),
this, SLOT(
cleanup()));
130 dialog.setText(tr(
"The ckb-next daemon is not running. This program will <b>not</b> work without it!"));
132 dialog.setIcon(QMessageBox::Critical);
139 QFileInfo rootDevPath(
devpath.arg(0));
140 if (!rootDevPath.exists()) {
151 #ifdef USE_LIBAPPINDICATOR
153 app_indicator_set_status(indicator, visible ? APP_INDICATOR_STATUS_ACTIVE : APP_INDICATOR_STATUS_PASSIVE);
155 #endif // USE_LIBAPPINDICATOR
199 QString daemonWarning;
200 if(daemonVersion != CKB_VERSION_STR)
223 metaObject()->invokeMethod(
this,
"showFwUpdateNotification", Qt::QueuedConnection, Q_ARG(
QWidget*, w), Q_ARG(
float, version));
231 static bool isShowing =
false;
238 if(QMessageBox::information(
this,
"Firmware update", tr(
"A new firmware is available for your %1 (v%2)\nWould you like to install it now?").arg(w->
device->
usbModel, QString::number(version,
'f', 2)), QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No), QMessageBox::Yes) == QMessageBox::Yes){
249 if(!event->spontaneous() || isHidden()){
254 QMessageBox::information(
this,
"ckb",
"ckb will still run in the background.\nTo close it, choose Exit from the tray menu\nor click \"Quit ckb\" on the Settings screen.");
265 QStringList commands = QString((
const char*)data).split(
"\n");
267 snprintf((
char*)
appShare.data(),
appShare.size(),
"PID %ld", (long)getpid());
270 foreach(
const QString& line, commands){
274 if(line.startsWith(
"Option ")){
276 QString option = line.split(
" ")[1];
280 else if(option ==
"Close")
299 if(reason == QSystemTrayIcon::DoubleClick || reason == QSystemTrayIcon::Trigger){
318 static quint64 lastStateChange = 0;
319 quint64 now = QDateTime::currentMSecsSinceEpoch();
320 if(state == Qt::ApplicationActive){
322 if(lastStateChange != 0 && now >= lastStateChange + 2 * 1000)
324 lastStateChange = now;
void stateChange(Qt::ApplicationState state)
static KbManager * kbManager()
void showFwUpdateNotification(QWidget *widget, float version)
static void set(const QString &key, const QVariant &value)
void closeEvent(QCloseEvent *event)
static QVariant get(const QString &key, const QVariant &defaultValue=QVariant())
void toggleTrayIcon(bool visible)
void removeDevice(Kb *device)
static QTimer * scanTimer()
static float ckbDaemonVersionF()
static const QString configLabel
MainWindow(QWidget *parent=0)
static float ckbGuiVersionF()
static void init(QString guiVersion)
QSystemTrayIcon * trayIcon
static MainWindow * mainWindow
static bool checkUpdates()
#define DAEMON_UNAVAILABLE_STR
void setupUi(QMainWindow *MainWindow)
void iconClicked(QSystemTrayIcon::ActivationReason reason)
SettingsWidget * settingsWidget
static QString ckbDaemonVersion()
QString devpath
Device path base ("/dev/input/ckb" or "/var/run/ckb")
QList< KbWidget * > kbWidgets
void addDevice(Kb *device)
static float versionForBoard(const QString &features, bool waitForComplete=false)