From 94ec7d34ff29029aa7cd289c9455f11099f55c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=20=E7=BF=94?= Date: Wed, 31 Jan 2018 18:20:56 +0800 Subject: [PATCH] read auto startup info --- plugins/startupmanager/startupdata.cpp | 90 ++ plugins/startupmanager/startupdata.h | 65 ++ plugins/startupmanager/startupitem.cpp | 35 +- plugins/startupmanager/startupitem.h | 5 +- plugins/startupmanager/startuplistwidget.cpp | 832 ++++++++---------- plugins/startupmanager/startuplistwidget.h | 13 +- plugins/startupmanager/startupmanager.cpp | 2 +- plugins/startupmanager/startupmanager.pro | 12 +- plugins/startupmanager/startuptitlewidget.cpp | 10 +- plugins/startupmanager/startupwidget.cpp | 27 + plugins/startupmanager/startupworker.cpp | 253 ++++++ plugins/startupmanager/startupworker.h | 59 ++ plugins/systemmonitor/filesystemdata.h | 7 +- plugins/systemmonitor/filesystemdialog.cpp | 13 + plugins/systemmonitor/filesystemdialog.h | 1 + .../systemmonitor/filesystemlistwidget.cpp | 4 +- plugins/systemmonitor/filesystemlistwidget.h | 2 - plugins/systemmonitor/filesystemworker.cpp | 2 +- plugins/systemmonitor/filesystemworker.h | 2 - plugins/systemmonitor/processdialog.cpp | 2 - plugins/systemmonitor/util.cpp | 8 +- 21 files changed, 968 insertions(+), 476 deletions(-) create mode 100644 plugins/startupmanager/startupdata.cpp create mode 100644 plugins/startupmanager/startupdata.h create mode 100644 plugins/startupmanager/startupworker.cpp create mode 100644 plugins/startupmanager/startupworker.h diff --git a/plugins/startupmanager/startupdata.cpp b/plugins/startupmanager/startupdata.cpp new file mode 100644 index 0000000..9dd8cea --- /dev/null +++ b/plugins/startupmanager/startupdata.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. + * + * Authors: + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "startupdata.h" +#include + +StartupData::StartupData(QObject *parent) + : QObject(parent) +{ +} + +//const QString FileSystemData::deviceName() const +//{ +// return m_devName; +//} + +//void FileSystemData::setDevName(const QString &name) +//{ +// if (name != m_devName) +// m_devName = name; +//} + +//const QString FileSystemData::mountDir() const +//{ +// return m_mountDir; +//} + +//const QString FileSystemData::diskType() const +//{ +// return m_diskType; +//} + +//const QString FileSystemData::totalCapacity() const +//{ +// return m_totalCapacity; +//} + +//const QString FileSystemData::freeCapacity() const +//{ +// return m_freeCapacity; +//} + +//const QString FileSystemData::availCapacity() const +//{ +// return m_availCapacity; +//} + +//const QString FileSystemData::usedCapactiy() const +//{ +// return m_usedCapactiy; +//} + +//const int FileSystemData::usedPercentage() +//{ +// return m_percentage; +//} + +void StartupData::updateStartupData(QString mountDir, QString diskType, QString totalCapacity, QString freeCapacity, QString availCapacity, QString usedCapactiy, int percentage) +{ +// if (mountDir != m_mountDir) +// m_mountDir = mountDir; +// if (diskType != m_diskType) +// m_diskType = diskType; +// if (totalCapacity != m_totalCapacity) +// m_totalCapacity = totalCapacity; +// if (freeCapacity != m_freeCapacity) +// m_freeCapacity = freeCapacity; +// if (availCapacity != m_availCapacity) +// m_availCapacity = availCapacity; +// if (usedCapactiy != m_usedCapactiy) +// m_usedCapactiy = usedCapactiy; +// if (percentage != m_percentage) +// m_percentage = percentage; +} diff --git a/plugins/startupmanager/startupdata.h b/plugins/startupmanager/startupdata.h new file mode 100644 index 0000000..13186e3 --- /dev/null +++ b/plugins/startupmanager/startupdata.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. + * + * Authors: + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef STARTUPDATA_H +#define STARTUPDATA_H + +#include +#include +#include +#include + +class StartupData +{ +public: + bool hidden; + bool no_display; + bool enabled; + bool shown; + + QString path; + QString basename; + QString name; + QString exec; + QString comment; + QString icon; + QString description; + + /* position of the directory in the XDG environment variable */ + unsigned int xdg_position; + /* position of the first system directory in the XDG env var containing + * this autostart app too (G_MAXUINT means none) */ + unsigned int xdg_system_position; + /* mask of what has changed */ + unsigned int save_mask = 0; + /* path that contains the original file that needs to be saved */ + QString old_system_path; +}; + + +typedef QSharedPointer StartupDataPtr; +typedef QList StartupDataPtrList; + +Q_DECLARE_METATYPE(StartupData) +Q_DECLARE_METATYPE(StartupDataPtr) +Q_DECLARE_METATYPE(StartupDataPtrList) + +#endif // STARTUPDATA_H + diff --git a/plugins/startupmanager/startupitem.cpp b/plugins/startupmanager/startupitem.cpp index 6756f0c..ec06b86 100644 --- a/plugins/startupmanager/startupitem.cpp +++ b/plugins/startupmanager/startupitem.cpp @@ -19,12 +19,34 @@ #include "startupitem.h" #include "../../component/kylinswitcher.h" +#include "startupdata.h" +#include #include #include #include -StartupItem::StartupItem(QWidget *parent) : QWidget(parent) +inline QPixmap getAppIconPix(const QString &iconName, int iconSize) +{ + QIcon defaultExecutableIcon = QIcon::fromTheme("application-x-executable"); + QIcon icon; + + if (iconName.contains("/")) { + icon = QIcon(iconName); + } + else { + icon = QIcon::fromTheme(iconName, defaultExecutableIcon); + } + + qreal devicePixelRatio = qApp->devicePixelRatio(); + + QPixmap pixmap = icon.pixmap(iconSize * devicePixelRatio, iconSize * devicePixelRatio); + pixmap.setDevicePixelRatio(devicePixelRatio); + + return pixmap; +} + +StartupItem::StartupItem(StartupData info, QWidget *parent) : QWidget(parent) ,isEntered(false) { item = new QListWidgetItem(); @@ -37,17 +59,20 @@ StartupItem::StartupItem(QWidget *parent) : QWidget(parent) m_appIcon = new QLabel(); m_appIcon->setFixedSize(40, 40); m_appIcon->setScaledContents(true);//自动缩放,显示图像大小自动调整为Qlabel大小 - m_appIcon->setPixmap(QPixmap("://res/ubuntukylin.png")); + m_appIcon->setPixmap(getAppIconPix(info.icon, 40)); m_appNameLabel = new QLabel(); + this->setAppName(info.name); m_appDescLabel = new QLabel(); - m_appDescLabel->setText("ppppp"); + m_appDescLabel->setText(info.comment); switcher = new KylinSwitcher(); - switcher->switchedOn = false; + switcher->switchedOn = info.enabled; +// connect(switcher, SIGNAL(clicked()), this, SLOT() connect(switcher, &KylinSwitcher::clicked, [=] () { + qDebug() << switcher->switchedOn; //changeAutoStartAppStatus - emit changeStartup(); + emit changeStartup(info.exec, switcher->switchedOn); }); m_switchLayout->addWidget(switcher, 0, Qt::AlignCenter); diff --git a/plugins/startupmanager/startupitem.h b/plugins/startupmanager/startupitem.h index fa81c51..af6f7b4 100644 --- a/plugins/startupmanager/startupitem.h +++ b/plugins/startupmanager/startupitem.h @@ -26,13 +26,14 @@ #include class KylinSwitcher; +class StartupData; class StartupItem : public QWidget { Q_OBJECT public: - StartupItem(QWidget *parent=0); + StartupItem(StartupData info, QWidget *parent=0); QListWidgetItem* getItem(); QString getAppName(); @@ -42,7 +43,7 @@ public: void unsetItemHovered(); signals: - void changeStartup(); + void changeStartup(const QString &exec, bool active); void enter(); protected: diff --git a/plugins/startupmanager/startuplistwidget.cpp b/plugins/startupmanager/startuplistwidget.cpp index 3e64de3..89c0903 100644 --- a/plugins/startupmanager/startuplistwidget.cpp +++ b/plugins/startupmanager/startuplistwidget.cpp @@ -25,445 +25,364 @@ #include #include #include - +#include +#include +#include #include #include #include #include #include - #include #include +#include "startupworker.h" -static char ** -gsm_util_get_standard_autostart_dirs (void) -{ - GPtrArray *dirs; - const char * const *system_config_dirs; - const char * const *system_data_dirs; - int i; +using namespace std; - dirs = g_ptr_array_new (); +///usr/share/gnome-session/sessions/ubuntu.session - g_ptr_array_add (dirs, - g_build_filename (g_get_user_config_dir (), - "autostart", NULL)); - system_data_dirs = g_get_system_data_dirs (); - for (i = 0; system_data_dirs[i]; i++) { - g_ptr_array_add (dirs, - g_build_filename (system_data_dirs[i], - "gnome", "autostart", NULL)); - } - - system_config_dirs = g_get_system_config_dirs (); - for (i = 0; system_config_dirs[i]; i++) { - g_ptr_array_add (dirs, - g_build_filename (system_config_dirs[i], - "autostart", NULL)); - } - - g_ptr_array_add (dirs, NULL); - - return (char **) g_ptr_array_free (dirs, FALSE); -} - -char ** -gsm_util_get_autostart_dirs () -{ -// if (autostart_dirs) { -// return g_strdupv ((char **)autostart_dirs); -// } - - return gsm_util_get_standard_autostart_dirs (); -} - -//static int -//gsp_app_manager_get_dir_index (GspAppManager *manager, -// const char *dir) +//static void _gsp_ensure_user_autostart_dir (void) //{ -// GSList *l; -// GspXdgDir *xdgdir; +// char *dir; -// g_return_val_if_fail (GSP_IS_APP_MANAGER (manager), -1); -// g_return_val_if_fail (dir != NULL, -1); +// dir = g_build_filename (g_get_user_config_dir (), "autostart", NULL); +// g_mkdir_with_parents (dir, S_IRWXU); -// for (l = manager->priv->dirs; l != NULL; l = l->next) { -// xdgdir = l->data; -// if (strcmp (dir, xdgdir->dir) == 0) { -// return xdgdir->index; -// } -// } - -// return -1; +// g_free (dir); //} - -//const char * -//gsp_app_manager_get_dir (GspAppManager *manager, -// unsigned int index) +//static inline void _gsp_app_save_done_success (GspApp *app) //{ -// GSList *l; -// GspXdgDir *xdgdir; +// app->priv->save_mask = 0; -// g_return_val_if_fail (GSP_IS_APP_MANAGER (manager), NULL); - -// for (l = manager->priv->dirs; l != NULL; l = l->next) { -// xdgdir = l->data; -// if (index == xdgdir->index) { -// return xdgdir->dir; -// } +// if (app->priv->old_system_path) { +// g_free (app->priv->old_system_path); +// app->priv->old_system_path = NULL; // } - -// return NULL; //} -//static gboolean -//gsp_app_manager_xdg_dir_monitor (GFileMonitor *monitor, -// GFile *child, -// GFile *other_file, -// GFileMonitorEvent flags, -// gpointer data) +//static gboolean _gsp_app_user_equal_system (GspApp *app, +// char **system_path) //{ // GspAppManager *manager; -// GspApp *old_app; -// GspApp *app; -// GFile *parent; -// char *basename; -// char *dir; +// const char *system_dir; // char *path; -// int index; +// char *str; +// GKeyFile *keyfile; -// manager = GSP_APP_MANAGER (data); - -// basename = g_file_get_basename (child); -// if (!g_str_has_suffix (basename, ".desktop")) { -// /* not a desktop file, we can ignore */ -// g_free (basename); -// return TRUE; -// } -// old_app = gsp_app_manager_find_app_with_basename (manager, basename); - -// parent = g_file_get_parent (child); -// dir = g_file_get_path (parent); -// g_object_unref (parent); - -// index = gsp_app_manager_get_dir_index (manager, dir); -// if (index < 0) { -// /* not a directory we know; should never happen, though */ -// g_free (dir); -// return TRUE; +// manager = gsp_app_manager_get (); +// system_dir = gsp_app_manager_get_dir (manager, +// app->priv->xdg_system_position); +// g_object_unref (manager); +// if (!system_dir) { +// return FALSE; // } -// path = g_file_get_path (child); +// path = g_build_filename (system_dir, app->priv->basename, NULL); -// switch (flags) { -// case G_FILE_MONITOR_EVENT_CHANGED: -// case G_FILE_MONITOR_EVENT_CREATED: -// /* we just do as if it was a new file: GspApp is clever enough -// * to do the right thing */ -// app = gsp_app_new (path, (unsigned int) index); - -// /* we didn't have this app before, so add it */ -// if (old_app == NULL && app != NULL) { -// gsp_app_manager_add (manager, app); -// g_object_unref (app); -// } -// /* else: it was just updated, GspApp took care of -// * sending the event */ -// break; -// case G_FILE_MONITOR_EVENT_DELETED: -// if (!old_app) { -// /* it got deleted, but we don't know about it, so -// * nothing to do */ -// break; -// } - -// _gsp_app_manager_handle_delete (manager, old_app, -// basename, index); -// break; -// default: -// break; +// keyfile = g_key_file_new (); +// if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL)) { +// g_free (path); +// g_key_file_free (keyfile); +// return FALSE; +// } +// if (gsp_key_file_get_boolean (keyfile, +// G_KEY_FILE_DESKTOP_KEY_HIDDEN, +// FALSE) != app->priv->hidden || +// gsp_key_file_get_boolean (keyfile, +// GSP_KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED, +// TRUE) != app->priv->enabled || +// gsp_key_file_get_shown (keyfile, +// _gsp_get_current_desktop ()) != app->priv->shown) { +// g_free (path); +// g_key_file_free (keyfile); +// return FALSE; // } -// g_free (path); -// g_free (dir); -// g_free (basename); +// if (gsp_key_file_get_boolean (keyfile, +// G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, +// FALSE) != app->priv->no_display) { +// g_free (path); +// g_key_file_free (keyfile); +// return FALSE; +// } + +// str = gsp_key_file_get_locale_string (keyfile, +// G_KEY_FILE_DESKTOP_KEY_NAME); +// if (!_gsp_str_equal (str, app->priv->name)) { +// g_free (str); +// g_free (path); +// g_key_file_free (keyfile); +// return FALSE; +// } +// g_free (str); +// str = gsp_key_file_get_locale_string (keyfile, +// G_KEY_FILE_DESKTOP_KEY_COMMENT); +// if (!_gsp_str_equal (str, app->priv->comment)) { +// g_free (str); +// g_free (path); +// g_key_file_free (keyfile); +// return FALSE; +// } +// g_free (str); + +// str = gsp_key_file_get_string (keyfile, +// G_KEY_FILE_DESKTOP_KEY_EXEC); +// if (!_gsp_str_equal (str, app->priv->exec)) { +// g_free (str); +// g_free (path); +// g_key_file_free (keyfile); +// return FALSE; +// } +// g_free (str); + +// str = gsp_key_file_get_locale_string (keyfile, +// G_KEY_FILE_DESKTOP_KEY_ICON); +// if (!_gsp_str_equal (str, app->priv->icon)) { +// g_free (str); +// g_free (path); +// g_key_file_free (keyfile); +// return FALSE; +// } +// g_free (str); + +// g_key_file_free (keyfile); + +// *system_path = path; // return TRUE; //} -//static void -//_gsp_app_manager_fill_from_dir (GspAppManager *manager, -// GspXdgDir *xdgdir) + +//static gboolean +//_gsp_app_save (gpointer data) //{ -// GFile *file; -// GDir *dir; -// const char *name; +// GspApp *app; +// char *use_path; +// GKeyFile *keyfile; +// GError *error; -// file = g_file_new_for_path (xdgdir->dir); -// xdgdir->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, -// NULL, NULL); -// g_object_unref (file); +// app = GSP_APP (data); -// if (xdgdir->monitor) { -// g_signal_connect (xdgdir->monitor, "changed", -// G_CALLBACK (gsp_app_manager_xdg_dir_monitor), -// manager); -// } - -// dir = g_dir_open (xdgdir->dir, 0, NULL); -// if (!dir) { -// return; -// } - -// while ((name = g_dir_read_name (dir))) { -// GspApp *app; -// char *desktop_file_path; - -// if (!g_str_has_suffix (name, ".desktop")) { -// continue; +// /* first check if removing the data from the user dir and using the +// * data from the system dir is enough -- this helps us keep clean the +// * user config dir by removing unneeded files */ +// if (_gsp_app_user_equal_system (app, &use_path)) { +// if (g_file_test (app->priv->path, G_FILE_TEST_EXISTS)) { +// g_remove (app->priv->path); // } -// desktop_file_path = g_build_filename (xdgdir->dir, name, NULL); -// app = gsp_app_new (desktop_file_path, xdgdir->index); +// g_free (app->priv->path); +// app->priv->path = use_path; -// if (app != NULL) { -// gsp_app_manager_add (manager, app); -// g_object_unref (app); -// } +// app->priv->xdg_position = app->priv->xdg_system_position; -// g_free (desktop_file_path); +// _gsp_app_save_done_success (app); +// return FALSE; // } -// g_dir_close (dir); +// if (app->priv->old_system_path) +// use_path = app->priv->old_system_path; +// else +// use_path = app->priv->path; + +// keyfile = g_key_file_new (); + +// error = NULL; +// g_key_file_load_from_file (keyfile, use_path, +// G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, +// &error); + +// if (error) { +// g_error_free (error); +// gsp_key_file_populate (keyfile); +// } + +// if (app->priv->save_mask & GSP_ASP_SAVE_MASK_HIDDEN) { +// gsp_key_file_set_boolean (keyfile, +// G_KEY_FILE_DESKTOP_KEY_HIDDEN, +// app->priv->hidden); +// } +// if (app->priv->save_mask & GSP_ASP_SAVE_MASK_NO_DISPLAY) { +// gsp_key_file_set_boolean (keyfile, +// G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, +// app->priv->no_display); +// } + +// if (app->priv->save_mask & GSP_ASP_SAVE_MASK_ENABLED) { +// gsp_key_file_set_boolean (keyfile, +// GSP_KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED, +// app->priv->enabled); +// } + +// if (app->priv->save_mask & GSP_ASP_SAVE_MASK_NAME) { +// gsp_key_file_set_locale_string (keyfile, +// G_KEY_FILE_DESKTOP_KEY_NAME, +// app->priv->name); +// gsp_key_file_ensure_C_key (keyfile, G_KEY_FILE_DESKTOP_KEY_NAME); +// } + +// if (app->priv->save_mask & GSP_ASP_SAVE_MASK_COMMENT) { +// gsp_key_file_set_locale_string (keyfile, +// G_KEY_FILE_DESKTOP_KEY_COMMENT, +// app->priv->comment); +// gsp_key_file_ensure_C_key (keyfile, G_KEY_FILE_DESKTOP_KEY_COMMENT); +// } + +// if (app->priv->save_mask & GSP_ASP_SAVE_MASK_EXEC) { +// gsp_key_file_set_string (keyfile, +// G_KEY_FILE_DESKTOP_KEY_EXEC, +// app->priv->exec); +// } +// _gsp_ensure_user_autostart_dir (); +// if (gsp_key_file_to_file (keyfile, app->priv->path, NULL)) { +// app->priv->skip_next_monitor_event = TRUE; +// _gsp_app_save_done_success (app); +// } else { +// g_warning ("Could not save %s file", app->priv->path); +// } + +// g_key_file_free (keyfile); + +// app->priv->save_timeout = 0; +// return FALSE; //} -void test_func() -{ - char **autostart_dirs; - int i; - autostart_dirs = gsm_util_get_autostart_dirs (); - /* we always assume that the first directory is the user one */ - g_assert (g_str_has_prefix (autostart_dirs[0], - g_get_user_config_dir ())); +//static void +//_gsp_app_queue_save (StartupData info/*GspApp *app*/) +//{ +// /* if the file was not in the user directory, then we'll create a copy +// * there */ +// if (info.xdg_position != 0) { +// info.xdg_position = 0; - for (i = 0; autostart_dirs[i] != NULL; i++) { -// GspXdgDir *xdgdir; - -// if (gsp_app_manager_get_dir_index (manager, -// autostart_dirs[i]) >= 0) { -// continue; +// if (info.old_system_path.isEmpty()) { +// info.old_system_path = info.path; +// /* if old_system_path was not NULL, then it means we +// * tried to save and we failed; in that case, we want +// * to try again and use the old file as a basis again */ // } -// xdgdir = _gsp_xdg_dir_new (autostart_dirs[i], i); -// manager->priv->dirs = g_slist_prepend (manager->priv->dirs, -// xdgdir); -// _gsp_app_manager_fill_from_dir (manager, xdgdir); - } - g_strfreev (autostart_dirs); -} - -//static void -//_fill_iter_from_app (GtkListStore *list_store, -// GtkTreeIter *iter, -// GspApp *app) -//{ -// gboolean hidden; -// gboolean display; -// gboolean enabled; -// gboolean shown; -// GIcon *icon; -// const char *description; -// const char *app_name; - -// hidden = gsp_app_get_hidden (app); -// display = gsp_app_get_display (app); -// enabled = gsp_app_get_enabled (app); -// shown = gsp_app_get_shown (app); -// icon = gsp_app_get_icon (app); -// description = gsp_app_get_description (app); -// app_name = gsp_app_get_name (app); - -// if (G_IS_THEMED_ICON (icon)) { -// GtkIconTheme *theme; -// const char * const *icon_names; - -// theme = gtk_icon_theme_get_default (); -// icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon)); -// if (icon_names[0] == NULL || -// !gtk_icon_theme_has_icon (theme, icon_names[0])) { -// g_object_unref (icon); -// icon = NULL; -// } -// } else if (G_IS_FILE_ICON (icon)) { -// GFile *iconfile; - -// iconfile = g_file_icon_get_file (G_FILE_ICON (icon)); -// if (!g_file_query_exists (iconfile, NULL)) { -// g_object_unref (icon); -// icon = NULL; -// } -// } - -// if (icon == NULL) { -// icon = g_themed_icon_new (STARTUP_APP_ICON); -// } - -// gtk_list_store_set (list_store, iter, -// STORE_COL_VISIBLE, !hidden && shown && display, -// STORE_COL_ENABLED, enabled, -// STORE_COL_GICON, icon, -// STORE_COL_DESCRIPTION, description, -// STORE_COL_APP, app, -// STORE_COL_SEARCH, app_name, -// -1); -// g_object_unref (icon); -//} -//static void -//append_app (GsmPropertiesDialog *dialog, -// GspApp *app) -//{ -// GtkTreeIter iter; - -// gtk_list_store_append (dialog->priv->list_store, &iter); -// _fill_iter_from_app (dialog->priv->list_store, &iter, app); - -// g_signal_connect_swapped (app, "changed", -// G_CALLBACK (_app_changed), dialog); -//} -//static void -//populate_model (GsmPropertiesDialog *dialog) -//{ -// GSList *apps; -// GSList *l; - -// apps = gsp_app_manager_get_apps (dialog->priv->manager); -// for (l = apps; l != NULL; l = l->next) { -// append_app (dialog, GSP_APP (l->data)); -// } -// g_slist_free (apps); -//} - -//populate_model (dialog); - -//inline QPixmap getDesktopFileIcon(QString desktopFile, int iconSize) -//{ -// std::string desktop_file; -// desktopFile = desktopFile.toStdString(); -// std::ifstream in; -// in.open(desktop_file); -// QIcon defaultExecutableIcon = QIcon::fromTheme("application-x-executable"); -// QIcon icon; -// QString iconName; -// while(!in.eof()) { -// std::string line; -// std::getline(in,line); -// iconName = QString::fromStdString(line); - -// if (iconName.startsWith("Icon=")) { -// iconName.remove(0,5); // remove the first 5 chars -// } else { -// continue; -// } - -// if (iconName.contains("/")) { -// icon = QIcon(iconName); -// } else { -// icon = QIcon::fromTheme(iconName, defaultExecutableIcon); -// break; -// } +// info.path = g_build_filename (g_get_user_config_dir (), +// "autostart", +// info.basename, NULL); // } -// in.close(); -// qreal devicePixelRatio = qApp->devicePixelRatio(); -// QPixmap pixmap = icon.pixmap(iconSize * devicePixelRatio, iconSize * devicePixelRatio); -// pixmap.setDevicePixelRatio(devicePixelRatio); +//// if (app->priv->save_timeout) { +//// g_source_remove (app->priv->save_timeout); +//// app->priv->save_timeout = 0; +//// } -// return pixmap; +//// /* if the file was not in the user directory, then we'll create a copy +//// * there */ +//// if (app->priv->xdg_position != 0) { +//// app->priv->xdg_position = 0; + +//// if (app->priv->old_system_path == NULL) { +//// app->priv->old_system_path = app->priv->path; +//// /* if old_system_path was not NULL, then it means we +//// * tried to save and we failed; in that case, we want +//// * to try again and use the old file as a basis again */ +//// } + +//// app->priv->path = g_build_filename (g_get_user_config_dir (), +//// "autostart", +//// app->priv->basename, NULL); +//// } + +//// app->priv->save_timeout = g_timeout_add_seconds (GSP_APP_SAVE_DELAY, +//// _gsp_app_save, +//// app); //} -inline QString getDesktopFile(QString processname) +//void +//gsp_app_delete (GspApp *app) +//{ +// g_return_if_fail (GSP_IS_APP (app)); + +// if (app->priv->xdg_position == 0 && +// app->priv->xdg_system_position == G_MAXUINT) { +// /* exists in user directory only */ +// if (app->priv->save_timeout) { +// g_source_remove (app->priv->save_timeout); +// app->priv->save_timeout = 0; +// } + +// if (g_file_test (app->priv->path, G_FILE_TEST_EXISTS)) { +// g_remove (app->priv->path); +// } + +// /* for extra safety */ +// app->priv->hidden = TRUE; +// app->priv->save_mask |= GSP_ASP_SAVE_MASK_HIDDEN; + +// _gsp_app_emit_removed (app); +// } else { +// /* also exists in system directory, so we have to keep a file +// * in the user directory */ +// app->priv->hidden = TRUE; +// app->priv->save_mask |= GSP_ASP_SAVE_MASK_HIDDEN; + +// _gsp_app_queue_save (app); +//// _gsp_app_emit_changed (app); +// } +//} + +std::string make_string(char *c_str) { - QDirIterator dir("/usr/share/applications", QDirIterator::Subdirectories); -// std::string desktopFile; - QString desktopFile; - - QString procname = processname.toLower(); - procname.replace("_", "-"); - - QString processFilename = procname + ".desktop"; - - while(dir.hasNext()) { - if (dir.fileInfo().suffix() == "desktop") { - if (dir.fileName().toLower().contains(processFilename)) { -// desktopFile = dir.filePath().toStdString(); - desktopFile = dir.filePath(); - break; - } - } - dir.next(); + if (!c_str) { + return string(); } - -// return QString::fromStdString(desktopFile); - return desktopFile; + string s(c_str); + g_free(c_str); + return s; } -//inline QString getDisplayNameFromName(QString procName, QString desktopFile, bool displayProcessName) -//{ -// QString procname = procName.toLower(); -// if (processDescriptions.contains(procname)) { -// if (displayProcessName) { -// return QString("%1 ( %2 )").arg(processDescriptions[procname], procName); -// } else { -// return processDescriptions[procname]; -// } -// } +inline QStringList autoStartDirectorys() +{ + QStringList dirList; + const gchar *config_dir = g_get_user_config_dir(); + std::string formatted_result(make_string(g_strdup(config_dir)));//std::string formatted_result = make_string(g_strdup(config_dir)); + dirList.append(QString::fromStdString(formatted_result)); -// if (desktopFile.size() == 0) { -// return procName; -// } + const char * const *system_config_dirs; + const char * const *system_data_dirs; + int i; + system_data_dirs = g_get_system_data_dirs(); + for (i = 0; system_data_dirs[i]; i++) { + std::string formatted_result(make_string(g_strdup(system_data_dirs[i]))); + QString dirPath = QString::fromStdString(formatted_result); + if (dirPath.endsWith("/")) + dirPath = QString("%1gnome/autostart").arg(dirPath); + else + dirPath = QString("%1/gnome/autostart").arg(dirPath); + if (!dirList.contains(dirPath) && QDir(dirPath).exists()) + dirList.append(dirPath); + } -// std::ifstream in; -// in.open(desktopFile); -// QString displayName = procName; -// while(!in.eof()) { -// std::string line; -// std::getline(in,line); + system_config_dirs = g_get_system_config_dirs(); + for (i = 0; system_config_dirs[i]; i++) { + std::string formatted_result(make_string(g_strdup(system_config_dirs[i]))); + QString dirPath = QString::fromStdString(formatted_result); + if (dirPath.endsWith("/")) + dirPath = dirPath + "autostart"; + else + dirPath = dirPath + QLatin1Char('/') + "autostart"; + if (!dirList.contains(dirPath) && QDir(dirPath).exists()) + dirList.append(dirPath); + } -// QString lineContent = QString::fromStdString(line); - -// QString localNameFlag = QString("Name[%1]=").arg(QLocale::system().name()); -// QString nameFlag = "Name="; -// QString genericNameFlag = QString("GenericName[%1]=").arg(QLocale::system().name()); - -// if (lineContent.startsWith(localNameFlag)) { -// displayName = lineContent.remove(0, localNameFlag.size()); - -// break; -// } else if (lineContent.startsWith(genericNameFlag)) { -// displayName = lineContent.remove(0, genericNameFlag.size()); -// break; -// } else if (lineContent.startsWith(nameFlag)) { -// displayName = lineContent.remove(0, nameFlag.size()); -// continue; -// } else { -// continue; -// } -// } -// in.close(); - -// return displayName; -//} + return dirList; +} StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent) { // this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - this->setFixedWidth(parent->width()); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -472,24 +391,53 @@ StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent) qDebug() << fileItem->getAppName(); }); -// loadItems(QStringList(), 0); - QStringList tmp; - tmp.append("AAA"); - tmp.append("BBB"); - tmp.append("CCC"); - tmp.append("DDD"); - tmp.append("EEE"); - tmp.append("FFF"); - tmp.append("GGG"); - tmp.append("HHH"); - tmp.append("JJJ"); - tmp.append("KKK"); - tmp.append("III"); - loadItems(tmp, 0); + + m_startupWorker = new StartupWorker; + m_startupWorker->moveToThread(qApp->thread()); + + QStringList autoDir = autoStartDirectorys(); + foreach (auto dir, autoDir) { +// qDebug() << "dir="< items; + this->clear(); + for (StartupData info : m_startupWorker->getStartupInfoList()) { + loadItem(info); + } + this->verticalScrollBar()->setValue(0); + +// qDebug()<<"GenericDataLocation=" << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); +// qDebug()<<"ConfigLocation=" << QStandardPaths::standardLocations(QStandardPaths::ConfigLocation); +// qDebug()<<"DocumentsLocation1=" << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); +// qDebug()<<"DocumentsLocation2=" << QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); +// qDebug()<<"PicturesLocation=" << QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); +// QStringList directory = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); +// qDebug()<<"HomeLocation=" <devicePixelRatio(); -// icon = findWindowTitle->getWindowIcon(findWindowTitle->getWindow(pid), 96 * devicePixelRatio); -// icon.setDevicePixelRatio(devicePixelRatio); -// } else { -// icon = getDesktopFileIcon(desktopFile, 96); -// } -// QString displayName = getDisplayNameFromName(name, desktopFile, false); - +// QString appName = ((StartupItem*) sender())->getAppName(); + StartupData data = m_startupWorker->getStartupInfo(exec); + this->setAppAutoStartup(data, active); } void StartupListWidget::onMouseEnter() diff --git a/plugins/startupmanager/startuplistwidget.h b/plugins/startupmanager/startuplistwidget.h index 24b3e3a..15de8f9 100644 --- a/plugins/startupmanager/startuplistwidget.h +++ b/plugins/startupmanager/startuplistwidget.h @@ -24,6 +24,9 @@ #include +class StartupWorker; +class StartupData; + class StartupListWidget : public QListWidget { Q_OBJECT @@ -32,12 +35,18 @@ public: StartupListWidget(QWidget *parent=0); ~StartupListWidget(); - void loadItem(QString info); + void loadItem(StartupData info); void loadItems(QStringList items, int scrollValue); + void listAllDesktopFileFromDir(QString directory); + void setAppAutoStartup(StartupData info, bool enabled); + public slots: - void onChangeStartup(); + void onChangeStartup(const QString &exec, bool active); void onMouseEnter(); + +private: + StartupWorker *m_startupWorker = nullptr; }; #endif // STARTUPLISTWIDGET_H diff --git a/plugins/startupmanager/startupmanager.cpp b/plugins/startupmanager/startupmanager.cpp index edf0de5..bb60842 100644 --- a/plugins/startupmanager/startupmanager.cpp +++ b/plugins/startupmanager/startupmanager.cpp @@ -32,7 +32,7 @@ //#sudo apt-get install sysv-rc-conf //运行:#sudo sysv-rc-conf -//gnome-session-properties +//gnome-session-properties(gnome-session-bin/gnome-session) StartupManager::StartupManager(QObject *parent) diff --git a/plugins/startupmanager/startupmanager.pro b/plugins/startupmanager/startupmanager.pro index 676b73c..d3734a1 100644 --- a/plugins/startupmanager/startupmanager.pro +++ b/plugins/startupmanager/startupmanager.pro @@ -30,19 +30,23 @@ HEADERS += \ startupwidget.h \ ../../component/plugininterface.h \ startuptitlewidget.h \ - ../widgets/myimagebutton.h \ + ../widgets/mytristatebutton.h \ startuplistwidget.h \ startupitem.h \ - ../../component/kylinswitcher.h + ../../component/kylinswitcher.h \ + startupworker.h \ + startupdata.h SOURCES += \ startupmanager.cpp \ startupwidget.cpp \ startuptitlewidget.cpp \ - ../widgets/myimagebutton.cpp \ + ../widgets/mytristatebutton.cpp \ startuplistwidget.cpp \ startupitem.cpp \ - ../../component/kylinswitcher.cpp + ../../component/kylinswitcher.cpp \ + startupworker.cpp +# startupdata.cpp OTHER_FILES += \ startupmanager.json diff --git a/plugins/startupmanager/startuptitlewidget.cpp b/plugins/startupmanager/startuptitlewidget.cpp index 8379ff6..7c45bba 100644 --- a/plugins/startupmanager/startuptitlewidget.cpp +++ b/plugins/startupmanager/startuptitlewidget.cpp @@ -18,7 +18,7 @@ */ #include "startuptitlewidget.h" -#include "../widgets/myimagebutton.h" +#include "../widgets/mytristatebutton.h" #include #include @@ -108,17 +108,17 @@ void StartupTitleWidget::initRightContent() m_layout->addWidget(w, 1, Qt::AlignRight); - MyImageButton *minBtn = new MyImageButton; + MyTristateButton *minBtn = new MyTristateButton; minBtn->setObjectName("MinButton"); - connect(minBtn, &MyImageButton::clicked, this, [=] { + connect(minBtn, &MyTristateButton::clicked, this, [=] { if (parentWidget() && parentWidget()->parentWidget()) { parentWidget()->parentWidget()->showMinimized(); } }); - MyImageButton *closeBtn = new MyImageButton; + MyTristateButton *closeBtn = new MyTristateButton; closeBtn->setObjectName("CloseButton"); - connect(closeBtn, &MyImageButton::clicked, this, [=] { + connect(closeBtn, &MyTristateButton::clicked, this, [=] { window()->close(); }); m_rLayout->addWidget(minBtn); diff --git a/plugins/startupmanager/startupwidget.cpp b/plugins/startupmanager/startupwidget.cpp index 874f721..e735777 100644 --- a/plugins/startupmanager/startupwidget.cpp +++ b/plugins/startupmanager/startupwidget.cpp @@ -20,6 +20,7 @@ #include "startupwidget.h" #include "startuptitlewidget.h" #include "startuplistwidget.h" +#include "startupdata.h" #include #include @@ -33,10 +34,36 @@ #include #include +QDataStream &operator<<(QDataStream &dataStream, const StartupDataPtr &object) +{ + auto ptr = object.data(); + auto ptrval = reinterpret_cast(ptr); + auto var = QVariant::fromValue(ptrval); + dataStream << var; + return dataStream; +} + +QDataStream &operator>>(QDataStream &dataStream, StartupDataPtr &object) +{ + QVariant var; + dataStream >> var; + qulonglong ptrval = var.toULongLong(); + auto ptr = reinterpret_cast(ptrval); + object = StartupDataPtr(ptr); + return dataStream; +} + + StartupWidget::StartupWidget(QWidget *parent) : QFrame(parent) , mousePressed(false) { + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + qRegisterMetaType(); + qRegisterMetaType>(); + + this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::WindowCloseButtonHint);//去掉边框 this->setAttribute(Qt::WA_TranslucentBackground);//背景透明 diff --git a/plugins/startupmanager/startupworker.cpp b/plugins/startupmanager/startupworker.cpp new file mode 100644 index 0000000..9a96cc5 --- /dev/null +++ b/plugins/startupmanager/startupworker.cpp @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. + * + * Authors: + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "startupworker.h" + +#include +#include +#include + +//#include +//static gboolean +//gsp_app_manager_xdg_dir_monitor (GFileMonitor *monitor, +// GFile *child, +// GFile *other_file, +// GFileMonitorEvent flags, +// gpointer data) +//{ +//// GspAppManager *manager; +//// GspApp *old_app; +//// GspApp *app; +// GFile *parent; +// char *basename; +// char *dir; +// char *path; +// int index; + +// manager = GSP_APP_MANAGER (data); + +// basename = g_file_get_basename (child); +// if (!g_str_has_suffix (basename, ".desktop")) { +// /* not a desktop file, we can ignore */ +// g_free (basename); +// return TRUE; +// } +// old_app = gsp_app_manager_find_app_with_basename (manager, basename); + +// parent = g_file_get_parent (child); +// dir = g_file_get_path (parent); +// g_object_unref (parent); + +// index = gsp_app_manager_get_dir_index (manager, dir); +// if (index < 0) { +// /* not a directory we know; should never happen, though */ +// g_free (dir); +// return TRUE; +// } + +// path = g_file_get_path (child); +// switch (flags) { +// case G_FILE_MONITOR_EVENT_CHANGED: +// case G_FILE_MONITOR_EVENT_CREATED: +// /* we just do as if it was a new file: GspApp is clever enough +// * to do the right thing */ +// app = gsp_app_new (path, (unsigned int) index); + +// /* we didn't have this app before, so add it */ +// if (old_app == NULL && app != NULL) { +// gsp_app_manager_add (manager, app); +// g_object_unref (app); +// } +// /* else: it was just updated, GspApp took care of +// * sending the event */ +// break; +// case G_FILE_MONITOR_EVENT_DELETED: +// if (!old_app) { +// /* it got deleted, but we don't know about it, so +// * nothing to do */ +// break; +// } + +// _gsp_app_manager_handle_delete (manager, old_app, +// basename, index); +// break; +// default: +// break; +// } + +// g_free (path); +// g_free (dir); +// g_free (basename); + +// return TRUE; +//} + +//GFileMonitor *monitor; +//monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); +//if (monitor) { +// g_signal_connect (monitor, "changed", G_CALLBACK (gsp_app_manager_xdg_dir_monitor), manager); +//} +//g_file_monitor_cancel (monitor); +//g_object_unref (monitor); +//monitor = NULL; + +inline QString getCurrentDesktopEnvironment() +{ + QString current_desktop; + + current_desktop = qgetenv("XDG_CURRENT_DESKTOP");//g_getenv + if(current_desktop.isEmpty()) { + current_desktop = qgetenv("XDG_SESSION_DESKTOP"); + if(current_desktop.isEmpty()) + current_desktop = "GNOME"; + } + + return current_desktop; +} + +bool getShownFromDesktopFile(const QString &desktopFile, const QString &desktopEnvironment) +{ + if (desktopEnvironment.isNull() || desktopEnvironment.isEmpty()) + return true; + + bool found; + QSettings setting(desktopFile, QSettings::IniFormat); + setting.beginGroup(KEY_FILE_DESKTOP_GROUP); + QStringList onlyShowIn = setting.value(KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN).toStringList(); + QStringList notShowIn = setting.value(KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN).toStringList(); + setting.endGroup(); + + if (!onlyShowIn.isEmpty()) { + found = false; + foreach (auto dekstopEnv, onlyShowIn) { + if (dekstopEnv == desktopEnvironment) { + found = true; + break; + } + } + if (!found) + return false; + } + + if (!notShowIn.isEmpty()) { + found = false; + foreach (auto dekstopEnv, notShowIn) { + if (dekstopEnv == desktopEnvironment) { + found = true; + break; + } + } + if (found) + return false; + } + + return true; +} + +StartupWorker::StartupWorker(QObject *parent) + : QObject(parent) +{ + +} + +StartupWorker::~StartupWorker() +{ + m_startupInfoList.clear(); +} + +void StartupWorker::addStartupInfo(const QString &desktopFile) +{ + QSettings setting(desktopFile, QSettings::IniFormat); + setting.beginGroup(KEY_FILE_DESKTOP_GROUP); + + bool hidden = setting.value(KEY_FILE_DESKTOP_KEY_HIDDEN, false).toBool(); + bool no_display = setting.value(KEY_FILE_DESKTOP_KEY_NO_DISPLAY, false).toBool(); + bool enabled = setting.value(KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED, true).toBool(); + bool shown = getShownFromDesktopFile(desktopFile, getCurrentDesktopEnvironment()); + QString basename = QFileInfo(desktopFile).fileName(); + QString name = setting.value(KEY_FILE_DESKTOP_KEY_NAME).toString(); + QString exec = setting.value(KEY_FILE_DESKTOP_KEY_EXEC).toString(); + QString comment = setting.value(KEY_FILE_DESKTOP_KEY_COMMENT).toString(); + QString icon = setting.value(KEY_FILE_DESKTOP_KEY_ICON).toString(); + if (name.isEmpty() || name.isNull()) + name = exec; + setting.endGroup(); + + //get description + QString primary; + QString secondary; + if (!name.isEmpty()) { + primary = name; + } else if (!exec.isEmpty()) { + primary = exec; + } else { + primary = tr("No name"); + } + if (!comment.isEmpty()) { + secondary = comment; + } else { + secondary = tr("No description"); + } + QString description = QString("%1\n%2").arg(primary).arg(secondary); + + StartupData info; + info.basename = basename; + info.path = desktopFile; + info.hidden = hidden; + info.no_display = no_display; + info.enabled = enabled; + info.shown = shown; + info.name = name; + info.exec = exec; + info.comment = comment; + info.icon = icon; + info.description = description; + + //printf("hidden=%s\n", hidden ? "Yes" : "No"); + + //show or hide + if (!hidden && shown && !no_display) { + //show +// if (isExecContains(exec)) { + +// } + m_startupInfoList[exec] = info; + + } + else { + //hide + if (isExecContains(exec)) + m_startupInfoList.remove(exec); + } +} + +bool StartupWorker::isExecContains(const QString &exec) +{ + return m_startupInfoList.keys().contains(exec); +} + +QList StartupWorker::getStartupInfoList() const +{ + return m_startupInfoList.values(); +} + +StartupData StartupWorker::getStartupInfo(const QString &exec) +{ + return m_startupInfoList.value(exec, StartupData());//nullptr +} diff --git a/plugins/startupmanager/startupworker.h b/plugins/startupmanager/startupworker.h new file mode 100644 index 0000000..2c64b38 --- /dev/null +++ b/plugins/startupmanager/startupworker.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. + * + * Authors: + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef STARTUPWORKER_H +#define STARTUPWORKER_H + +#include +#include + +#include "startupdata.h" + +#define KEY_FILE_DESKTOP_GROUP "Desktop Entry" +#define KEY_FILE_DESKTOP_KEY_HIDDEN "Hidden" +#define KEY_FILE_DESKTOP_KEY_NO_DISPLAY "NoDisplay" +#define KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "OnlyShowIn" +#define KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "NotShowIn" +#define KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED "X-GNOME-Autostart-enabled" +#define KEY_FILE_DESKTOP_KEY_NAME "Name" +#define KEY_FILE_DESKTOP_KEY_EXEC "Exec" +#define KEY_FILE_DESKTOP_KEY_COMMENT "Comment" +#define KEY_FILE_DESKTOP_KEY_ICON "Icon" + +#define SAVE_MASK_ENABLED 0x0002 + +class StartupWorker : public QObject +{ + Q_OBJECT + +public: + explicit StartupWorker(QObject *parent = 0); + ~StartupWorker(); + void addStartupInfo(const QString &desktopFile); + bool isExecContains(const QString &exec); + QList getStartupInfoList() const; + StartupData getStartupInfo(const QString &exec); + +private: + QMap m_startupInfoList; +}; + +#endif // STARTUPWORKER_H + diff --git a/plugins/systemmonitor/filesystemdata.h b/plugins/systemmonitor/filesystemdata.h index 9b3fb17..4b01761 100644 --- a/plugins/systemmonitor/filesystemdata.h +++ b/plugins/systemmonitor/filesystemdata.h @@ -18,8 +18,8 @@ */ -#ifndef DISKINFO_H -#define DISKINFO_H +#ifndef FILESYSTEMDATA_H +#define FILESYSTEMDATA_H #include #include @@ -55,6 +55,5 @@ private: int m_percentage; }; - -#endif // DISKINFO_H +#endif // FILESYSTEMDATA_H diff --git a/plugins/systemmonitor/filesystemdialog.cpp b/plugins/systemmonitor/filesystemdialog.cpp index 9de8922..eb160cd 100644 --- a/plugins/systemmonitor/filesystemdialog.cpp +++ b/plugins/systemmonitor/filesystemdialog.cpp @@ -60,12 +60,25 @@ FileSystemDialog::FileSystemDialog(QList toBeDisplayedColumns, QSettings * m_menu->addAction(m_refreshAction); this->refreshFileSysList(); + + //refresh file system info every 5 minutes + m_timer = new QTimer(this); + connect(m_timer,SIGNAL(timeout()),this,SLOT(refreshFileSysList())); + m_timer->start(5000); } FileSystemDialog::~FileSystemDialog() { // m_fileSystemMonitor->removePath(m_monitorFile); // delete m_fileSystemMonitor; + if (m_timer != NULL) { + disconnect(m_timer,SIGNAL(timeout()),this,SLOT(refreshProcproperties())); + if(m_timer->isActive()) { + m_timer->stop(); + } + delete m_timer; + m_timer = NULL; + } m_fileSystemWorker->deleteLater(); delete m_fileSysListWidget; diff --git a/plugins/systemmonitor/filesystemdialog.h b/plugins/systemmonitor/filesystemdialog.h index c4af161..ff6d262 100644 --- a/plugins/systemmonitor/filesystemdialog.h +++ b/plugins/systemmonitor/filesystemdialog.h @@ -64,4 +64,5 @@ private: QAction *m_refreshAction = nullptr; QMenu *m_menu = nullptr; QVBoxLayout *m_layout = nullptr; + QTimer *m_timer = nullptr; }; diff --git a/plugins/systemmonitor/filesystemlistwidget.cpp b/plugins/systemmonitor/filesystemlistwidget.cpp index e990853..6f765db 100644 --- a/plugins/systemmonitor/filesystemlistwidget.cpp +++ b/plugins/systemmonitor/filesystemlistwidget.cpp @@ -193,8 +193,8 @@ void FileSystemListWidget::mouseDoubleClickEvent(QMouseEvent *event) } if (pressInSelectionArea) { //open the mount dir - FileSystemListItem *procItem = static_cast(pressItem); - QString targetPath = QString("file://%1").arg(procItem->getDirectory()); + FileSystemListItem *item = static_cast(pressItem); + QString targetPath = QString("file://%1").arg(item->getDirectory()); QDesktopServices::openUrl(QUrl(targetPath));//xdg-open } } diff --git a/plugins/systemmonitor/filesystemlistwidget.h b/plugins/systemmonitor/filesystemlistwidget.h index 5d25010..1caa6a5 100644 --- a/plugins/systemmonitor/filesystemlistwidget.h +++ b/plugins/systemmonitor/filesystemlistwidget.h @@ -74,8 +74,6 @@ protected: private: QTimer *m_hideScrollbarTimer = nullptr; -// SearchFunction m_searchFunc; - FileSystemListItem *m_lastItem = nullptr; QList *m_listItems; QList *m_selectedItems; diff --git a/plugins/systemmonitor/filesystemworker.cpp b/plugins/systemmonitor/filesystemworker.cpp index 8027737..91cfd94 100644 --- a/plugins/systemmonitor/filesystemworker.cpp +++ b/plugins/systemmonitor/filesystemworker.cpp @@ -204,5 +204,5 @@ void FileSystemWorker::removeDiskItem(const QString &devname) bool FileSystemWorker::isDeviceContains(const QString &devname) { - return m_diskInfoList.contains(devname); + return m_diskInfoList.keys().contains(devname); } diff --git a/plugins/systemmonitor/filesystemworker.h b/plugins/systemmonitor/filesystemworker.h index e390cb5..c7cfa54 100644 --- a/plugins/systemmonitor/filesystemworker.h +++ b/plugins/systemmonitor/filesystemworker.h @@ -44,11 +44,9 @@ public: public slots: void onFileSystemListChanged(); - void removeUserByName(const QString &name); private: QMap m_diskInfoList; -// QMap *processSentBytes; }; #endif // FILESYSTEMWORKER_H diff --git a/plugins/systemmonitor/processdialog.cpp b/plugins/systemmonitor/processdialog.cpp index ea82a4e..45aea9e 100644 --- a/plugins/systemmonitor/processdialog.cpp +++ b/plugins/systemmonitor/processdialog.cpp @@ -34,8 +34,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/plugins/systemmonitor/util.cpp b/plugins/systemmonitor/util.cpp index 6c560e4..2203d6c 100644 --- a/plugins/systemmonitor/util.cpp +++ b/plugins/systemmonitor/util.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -131,12 +132,15 @@ QPixmap getAppIconFromDesktopFile(std::string desktopFile, int iconSize) if (iconName.startsWith("Icon=")) { iconName.remove(0,5); - } else { + } + else { continue; } + if (iconName.contains("/")) { icon = QIcon(iconName); - } else { + } + else { icon = QIcon::fromTheme(iconName, defaultExecutableIcon); break; }