forked from openkylin/quarkai
autostartup
This commit is contained in:
parent
94ec7d34ff
commit
364aeff7a2
|
@ -1,5 +1,5 @@
|
|||
TEMPLATE = subdirs
|
||||
SUBDIRS = \
|
||||
shredmanager \
|
||||
systemmonitor
|
||||
# startupmanager
|
||||
systemmonitor \
|
||||
startupmanager
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "startupdata.h"
|
||||
#include <QDebug>
|
||||
|
||||
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;
|
||||
}
|
|
@ -25,9 +25,14 @@
|
|||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QSharedPointer>
|
||||
#include <glib.h>
|
||||
|
||||
class StartupData
|
||||
class StartupData/* : public QObject*/
|
||||
{
|
||||
// Q_OBJECT
|
||||
//public:
|
||||
// explicit StartupData(QObject *parent = 0);
|
||||
|
||||
public:
|
||||
bool hidden;
|
||||
bool no_display;
|
||||
|
@ -43,14 +48,17 @@ public:
|
|||
QString description;
|
||||
|
||||
/* position of the directory in the XDG environment variable */
|
||||
unsigned int xdg_position;
|
||||
unsigned int xdg_position = G_MAXUINT;
|
||||
/* 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;
|
||||
unsigned int xdg_system_position = G_MAXUINT;
|
||||
/* mask of what has changed */
|
||||
unsigned int save_mask = 0;
|
||||
unsigned int save_mask = 0;
|
||||
/* path that contains the original file that needs to be saved */
|
||||
QString old_system_path;
|
||||
|
||||
public:
|
||||
void setEnabled(bool b) { this->enabled = b; }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -37,312 +37,9 @@
|
|||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "startupworker.h"
|
||||
// /usr/share/gnome-session/sessions/ubuntu.session
|
||||
|
||||
using namespace std;
|
||||
|
||||
///usr/share/gnome-session/sessions/ubuntu.session
|
||||
|
||||
|
||||
//static void _gsp_ensure_user_autostart_dir (void)
|
||||
//{
|
||||
// char *dir;
|
||||
|
||||
// dir = g_build_filename (g_get_user_config_dir (), "autostart", NULL);
|
||||
// g_mkdir_with_parents (dir, S_IRWXU);
|
||||
|
||||
// g_free (dir);
|
||||
//}
|
||||
|
||||
//static inline void _gsp_app_save_done_success (GspApp *app)
|
||||
//{
|
||||
// app->priv->save_mask = 0;
|
||||
|
||||
// if (app->priv->old_system_path) {
|
||||
// g_free (app->priv->old_system_path);
|
||||
// app->priv->old_system_path = NULL;
|
||||
// }
|
||||
//}
|
||||
|
||||
//static gboolean _gsp_app_user_equal_system (GspApp *app,
|
||||
// char **system_path)
|
||||
//{
|
||||
// GspAppManager *manager;
|
||||
// const char *system_dir;
|
||||
// char *path;
|
||||
// char *str;
|
||||
// GKeyFile *keyfile;
|
||||
|
||||
// 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_build_filename (system_dir, app->priv->basename, NULL);
|
||||
|
||||
// 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;
|
||||
// }
|
||||
|
||||
// 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 gboolean
|
||||
//_gsp_app_save (gpointer data)
|
||||
//{
|
||||
// GspApp *app;
|
||||
// char *use_path;
|
||||
// GKeyFile *keyfile;
|
||||
// GError *error;
|
||||
|
||||
// app = GSP_APP (data);
|
||||
|
||||
// /* 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);
|
||||
// }
|
||||
|
||||
// g_free (app->priv->path);
|
||||
// app->priv->path = use_path;
|
||||
|
||||
// app->priv->xdg_position = app->priv->xdg_system_position;
|
||||
|
||||
// _gsp_app_save_done_success (app);
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// 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;
|
||||
//}
|
||||
|
||||
//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;
|
||||
|
||||
// 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 */
|
||||
// }
|
||||
|
||||
// info.path = g_build_filename (g_get_user_config_dir (),
|
||||
// "autostart",
|
||||
// info.basename, NULL);
|
||||
// }
|
||||
|
||||
|
||||
//// if (app->priv->save_timeout) {
|
||||
//// g_source_remove (app->priv->save_timeout);
|
||||
//// app->priv->save_timeout = 0;
|
||||
//// }
|
||||
|
||||
//// /* 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);
|
||||
//}
|
||||
|
||||
//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)
|
||||
{
|
||||
if (!c_str) {
|
||||
return string();
|
||||
}
|
||||
string s(c_str);
|
||||
g_free(c_str);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline QStringList autoStartDirectorys()
|
||||
inline QStringList autoStartupDirectorys()
|
||||
{
|
||||
QStringList dirList;
|
||||
const gchar *config_dir = g_get_user_config_dir();
|
||||
|
@ -379,7 +76,6 @@ inline QStringList autoStartDirectorys()
|
|||
return dirList;
|
||||
}
|
||||
|
||||
|
||||
StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent)
|
||||
{
|
||||
// this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
@ -395,16 +91,42 @@ StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent)
|
|||
m_startupWorker = new StartupWorker;
|
||||
m_startupWorker->moveToThread(qApp->thread());
|
||||
|
||||
QStringList autoDir = autoStartDirectorys();
|
||||
|
||||
//gsp_app_manager_fill
|
||||
QStringList autoDir = autoStartupDirectorys();
|
||||
int i = 0;
|
||||
/*QList<QString>::Iterator it = autoDir.begin(), itend = autoDir.end();
|
||||
for(;it != itend; it++,i++) {
|
||||
qDebug() << *it;
|
||||
}*/
|
||||
foreach (auto dir, autoDir) {
|
||||
// qDebug() << "dir="<<dir;
|
||||
listAllDesktopFileFromDir(dir);
|
||||
GspXdgDir xdgDir;
|
||||
if (m_startupWorker->getDirIndex(dir) >= 0) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
xdgDir.dir = dir;
|
||||
xdgDir.index = i;
|
||||
i++;
|
||||
m_startupWorker->AddDirWithIndex(xdgDir);//append dir
|
||||
listAllDesktopFileFromDir(xdgDir);
|
||||
// GspXdgDir *xdgdir;
|
||||
// if (gsp_app_manager_get_dir_index (manager, autostart_dirs[i]) >= 0) {
|
||||
// continue;
|
||||
// }
|
||||
// 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);
|
||||
}
|
||||
|
||||
// QList<FileSystemListItem*> items;
|
||||
this->clear();
|
||||
for (StartupData info : m_startupWorker->getStartupInfoList()) {
|
||||
loadItem(info);
|
||||
//show or hide
|
||||
if (!info.hidden && info.shown && !info.no_display) {
|
||||
//show
|
||||
loadItem(info);
|
||||
}
|
||||
}
|
||||
this->verticalScrollBar()->setValue(0);
|
||||
|
||||
|
@ -447,49 +169,34 @@ StartupListWidget::~StartupListWidget()
|
|||
}
|
||||
}
|
||||
|
||||
void StartupListWidget::listAllDesktopFileFromDir(QString directory)
|
||||
//_gsp_app_manager_fill_from_dir
|
||||
void StartupListWidget::listAllDesktopFileFromDir(GspXdgDir xdgDir)
|
||||
{
|
||||
QDirIterator dir(directory, QDirIterator::Subdirectories);
|
||||
QDirIterator dir(xdgDir.dir, QDirIterator::Subdirectories);
|
||||
|
||||
while(dir.hasNext()) {
|
||||
if (dir.fileInfo().suffix() == "desktop") {
|
||||
QString desktopFile = dir.filePath();//dir.fileName().toLower()
|
||||
// qDebug() << "desktopFile="<<desktopFile;
|
||||
m_startupWorker->addStartupInfo(desktopFile);
|
||||
m_startupWorker->newStartupInfo(desktopFile, xdgDir.index);
|
||||
}
|
||||
dir.next();
|
||||
}
|
||||
}
|
||||
|
||||
//gsp_app_set_enabled (gboolean enabled)
|
||||
void StartupListWidget::setAppAutoStartup(StartupData info, bool enabled)
|
||||
void StartupListWidget::setAppAutoStartup(/*StartupData info,*/const QString &exec, bool enabled)
|
||||
{
|
||||
StartupData info = m_startupWorker->getStartupInfo(exec);
|
||||
// qDebug() << "info.enabled="<<info.enabled << ",enabled="<<enabled;
|
||||
if (info.enabled == enabled)
|
||||
return;
|
||||
|
||||
info.enabled = enabled;
|
||||
info.save_mask |= SAVE_MASK_ENABLED;
|
||||
|
||||
// _gsp_app_queue_save (info);
|
||||
|
||||
|
||||
// static void
|
||||
// _app_changed (GsmPropertiesDialog *dialog,
|
||||
// GspApp *app)
|
||||
// {
|
||||
// GtkTreeIter iter;
|
||||
|
||||
// if (!find_by_app (GTK_TREE_MODEL (dialog->priv->list_store),
|
||||
// &iter, app)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// _fill_iter_from_app (dialog->priv->list_store, &iter, app);
|
||||
// }
|
||||
|
||||
// _gsp_app_emit_changed (app);//g_signal_emit (G_OBJECT (app), gsp_app_signals[CHANGED], 0);
|
||||
|
||||
|
||||
m_startupWorker->updateEnable(info.exec, info.enabled);
|
||||
m_startupWorker->updateSaveMask(info.exec, info.save_mask);
|
||||
m_startupWorker->_gsp_app_queue_save(info);
|
||||
}
|
||||
|
||||
void StartupListWidget::loadItem(StartupData info)
|
||||
|
@ -516,8 +223,8 @@ void StartupListWidget::loadItems(QStringList items, int scrollValue)
|
|||
void StartupListWidget::onChangeStartup(const QString &exec, bool active)
|
||||
{
|
||||
// QString appName = ((StartupItem*) sender())->getAppName();
|
||||
StartupData data = m_startupWorker->getStartupInfo(exec);
|
||||
this->setAppAutoStartup(data, active);
|
||||
// StartupData data = m_startupWorker->getStartupInfo(exec);
|
||||
this->setAppAutoStartup(/*data,*/exec, active);
|
||||
}
|
||||
|
||||
void StartupListWidget::onMouseEnter()
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#define STARTUPLISTWIDGET_H
|
||||
|
||||
#include "startupitem.h"
|
||||
#include "startupworker.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
|
@ -38,8 +40,8 @@ public:
|
|||
void loadItem(StartupData info);
|
||||
void loadItems(QStringList items, int scrollValue);
|
||||
|
||||
void listAllDesktopFileFromDir(QString directory);
|
||||
void setAppAutoStartup(StartupData info, bool enabled);
|
||||
void listAllDesktopFileFromDir(GspXdgDir xdgDir);
|
||||
void setAppAutoStartup(/*StartupData info,*/const QString &exec, bool enabled);
|
||||
|
||||
public slots:
|
||||
void onChangeStartup(const QString &exec, bool active);
|
||||
|
|
|
@ -16,6 +16,8 @@ DESTDIR = $$_PRO_FILE_PWD_/../
|
|||
CONFIG += plugin c++11 link_pkgconfig
|
||||
PKGCONFIG += glib-2.0 gobject-2.0
|
||||
|
||||
QMAKE_CXXFLAGS += -fpermissive
|
||||
|
||||
target.path = $${PREFIX}/lib/kylin-assistant/plugins/
|
||||
INSTALLS += target
|
||||
|
||||
|
@ -35,7 +37,8 @@ HEADERS += \
|
|||
startupitem.h \
|
||||
../../component/kylinswitcher.h \
|
||||
startupworker.h \
|
||||
startupdata.h
|
||||
startupdata.h \
|
||||
util.h
|
||||
|
||||
SOURCES += \
|
||||
startupmanager.cpp \
|
||||
|
@ -45,8 +48,9 @@ SOURCES += \
|
|||
startuplistwidget.cpp \
|
||||
startupitem.cpp \
|
||||
../../component/kylinswitcher.cpp \
|
||||
startupworker.cpp
|
||||
# startupdata.cpp
|
||||
startupworker.cpp \
|
||||
# startupdata.cpp \
|
||||
util.cpp
|
||||
|
||||
OTHER_FILES += \
|
||||
startupmanager.json
|
||||
|
|
|
@ -23,6 +23,210 @@
|
|||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <glib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include "util.h"
|
||||
|
||||
|
||||
#define gsp_key_file_get_string(key_file, key) \
|
||||
g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL)
|
||||
#define gsp_key_file_get_locale_string(key_file, key) \
|
||||
g_key_file_get_locale_string(key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL, NULL)
|
||||
|
||||
#define gsp_key_file_set_boolean(key_file, key, value) \
|
||||
g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, key, value)
|
||||
#define gsp_key_file_set_string(key_file, key, value) \
|
||||
g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, key, value)
|
||||
|
||||
gboolean gsp_key_file_get_boolean (GKeyFile *keyfile,
|
||||
const gchar *key,
|
||||
gboolean default_value)
|
||||
{
|
||||
GError *error;
|
||||
gboolean retval;
|
||||
|
||||
error = NULL;
|
||||
retval = g_key_file_get_boolean (keyfile, G_KEY_FILE_DESKTOP_GROUP,
|
||||
key, &error);
|
||||
if (error != NULL) {
|
||||
retval = default_value;
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gboolean gsp_key_file_to_file (GKeyFile *keyfile,
|
||||
const gchar *path,
|
||||
GError **error)
|
||||
{
|
||||
GError *write_error;
|
||||
gchar *data;
|
||||
gsize length;
|
||||
gboolean res;
|
||||
|
||||
g_return_val_if_fail (keyfile != NULL, FALSE);
|
||||
g_return_val_if_fail (path != NULL, FALSE);
|
||||
|
||||
write_error = NULL;
|
||||
data = g_key_file_to_data (keyfile, &length, &write_error);
|
||||
|
||||
if (write_error) {
|
||||
g_propagate_error (error, write_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
res = g_file_set_contents (path, data, length, &write_error);
|
||||
g_free (data);
|
||||
|
||||
if (write_error) {
|
||||
g_propagate_error (error, write_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void gsp_key_file_populate (GKeyFile *keyfile)
|
||||
{
|
||||
gsp_key_file_set_string (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_TYPE,
|
||||
"Application");
|
||||
|
||||
gsp_key_file_set_string (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_EXEC,
|
||||
"/bin/false");
|
||||
}
|
||||
|
||||
void gsp_key_file_set_locale_string (GKeyFile *keyfile,
|
||||
const gchar *key,
|
||||
const gchar *value)
|
||||
{
|
||||
const char *locale;
|
||||
const char * const *langs_pointer;
|
||||
int i;
|
||||
|
||||
if (value == NULL) {
|
||||
value = "";
|
||||
}
|
||||
|
||||
locale = NULL;
|
||||
langs_pointer = g_get_language_names ();
|
||||
for (i = 0; langs_pointer[i] != NULL; i++) {
|
||||
/* find first without encoding */
|
||||
if (strchr (langs_pointer[i], '.') == NULL) {
|
||||
locale = langs_pointer[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (locale != NULL) {
|
||||
g_key_file_set_locale_string (keyfile, G_KEY_FILE_DESKTOP_GROUP,
|
||||
key, locale, value);
|
||||
} else {
|
||||
g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP,
|
||||
key, value);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean gsp_key_file_get_shown (GKeyFile *keyfile,
|
||||
const char *current_desktop)
|
||||
{
|
||||
char **only_show_in, **not_show_in;
|
||||
gboolean found;
|
||||
int i;
|
||||
|
||||
if (!current_desktop)
|
||||
return TRUE;
|
||||
|
||||
only_show_in = g_key_file_get_string_list (keyfile, G_KEY_FILE_DESKTOP_GROUP,
|
||||
G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN,
|
||||
NULL, NULL);
|
||||
|
||||
if (only_show_in) {
|
||||
found = FALSE;
|
||||
for (i = 0; only_show_in[i] != NULL; i++) {
|
||||
if (g_strcmp0 (current_desktop, only_show_in[i]) == 0) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (only_show_in);
|
||||
|
||||
if (!found)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
not_show_in = g_key_file_get_string_list (keyfile, G_KEY_FILE_DESKTOP_GROUP,
|
||||
G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN,
|
||||
NULL, NULL);
|
||||
if (not_show_in) {
|
||||
found = FALSE;
|
||||
for (i = 0; not_show_in[i] != NULL; i++) {
|
||||
if (g_strcmp0 (current_desktop, not_show_in[i]) == 0) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (not_show_in);
|
||||
|
||||
if (found)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static char *_gsp_get_current_desktop ()
|
||||
{
|
||||
static char *current_desktop = NULL;
|
||||
|
||||
/* Support XDG_CURRENT_DESKTOP environment variable; this can be used
|
||||
* to abuse gnome-session in non-GNOME desktops. */
|
||||
if (!current_desktop) {
|
||||
const char *desktop;
|
||||
|
||||
desktop = g_getenv ("XDG_CURRENT_DESKTOP");
|
||||
|
||||
/* Note: if XDG_CURRENT_DESKTOP is set but empty, do as if it
|
||||
* was not set */
|
||||
if (!desktop || desktop[0] == '\0')
|
||||
current_desktop = g_strdup ("GNOME");
|
||||
else
|
||||
current_desktop = g_strdup (desktop);
|
||||
}
|
||||
|
||||
/* Using "*" means skipping desktop-related checks */
|
||||
if (g_strcmp0 (current_desktop, "*") == 0)
|
||||
return NULL;
|
||||
|
||||
return current_desktop;
|
||||
}
|
||||
|
||||
static gboolean _gsp_str_equal (const char *a,
|
||||
const char *b)
|
||||
{
|
||||
if (g_strcmp0 (a, b) == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (a && !b && a[0] == '\0') {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (b && !a && b[0] == '\0') {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//#include <gio/gio.h>
|
||||
//static gboolean
|
||||
//gsp_app_manager_xdg_dir_monitor (GFileMonitor *monitor,
|
||||
|
@ -107,6 +311,27 @@
|
|||
//g_object_unref (monitor);
|
||||
//monitor = NULL;
|
||||
|
||||
|
||||
void gsp_key_file_ensure_C_key (GKeyFile *keyfile, const char *key)
|
||||
{
|
||||
char *C_value;
|
||||
char *buffer;
|
||||
|
||||
/* Make sure we set the "C" locale strings to the terms we set here.
|
||||
* This is so that if the user logs into another locale they get their
|
||||
* own description there rather then empty. It is not the C locale
|
||||
* however, but the user created this entry herself so it's OK */
|
||||
C_value = gsp_key_file_get_string (keyfile, key);
|
||||
if (C_value == NULL || C_value [0] == '\0') {
|
||||
buffer = gsp_key_file_get_locale_string (keyfile, key);
|
||||
if (buffer) {
|
||||
gsp_key_file_set_string (keyfile, key, buffer);
|
||||
g_free (buffer);
|
||||
}
|
||||
}
|
||||
g_free (C_value);
|
||||
}
|
||||
|
||||
inline QString getCurrentDesktopEnvironment()
|
||||
{
|
||||
QString current_desktop;
|
||||
|
@ -128,6 +353,7 @@ bool getShownFromDesktopFile(const QString &desktopFile, const QString &desktopE
|
|||
|
||||
bool found;
|
||||
QSettings setting(desktopFile, QSettings::IniFormat);
|
||||
setting.setIniCodec("UTF-8");
|
||||
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();
|
||||
|
@ -169,25 +395,117 @@ StartupWorker::StartupWorker(QObject *parent)
|
|||
StartupWorker::~StartupWorker()
|
||||
{
|
||||
m_startupInfoList.clear();
|
||||
this->dirs.clear();
|
||||
}
|
||||
|
||||
void StartupWorker::addStartupInfo(const QString &desktopFile)
|
||||
void StartupWorker::AddDirWithIndex(GspXdgDir dir)
|
||||
{
|
||||
QSettings setting(desktopFile, QSettings::IniFormat);
|
||||
this->dirs.append(dir);
|
||||
}
|
||||
|
||||
int StartupWorker::getDirIndex(QString dir)
|
||||
{
|
||||
foreach (GspXdgDir item, this->dirs) {
|
||||
if (item.dir == dir) {
|
||||
return item.index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString StartupWorker::gsp_app_manager_get_dir(unsigned int index)
|
||||
{
|
||||
foreach (GspXdgDir item, this->dirs) {
|
||||
if (item.index == index) {
|
||||
return item.dir;
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
StartupData StartupWorker::gsp_app_manager_find_app_with_basename(QString &basename)
|
||||
{
|
||||
for (StartupData info : this->getStartupInfoList()) {
|
||||
if (info.basename == basename) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
return StartupData();
|
||||
}
|
||||
|
||||
void StartupWorker::newStartupInfo(const QString &desktopFile, unsigned int xdg_position)
|
||||
{
|
||||
bool isNew;
|
||||
QString basename = QFileInfo(desktopFile).fileName();
|
||||
|
||||
StartupData info = gsp_app_manager_find_app_with_basename(basename);
|
||||
if (info.basename.isEmpty() && info.name.isEmpty() && info.exec.isEmpty())
|
||||
isNew = true;
|
||||
else
|
||||
isNew = false;
|
||||
|
||||
if (!isNew) {
|
||||
if (info.xdg_position == xdg_position) {
|
||||
// if (app->priv->skip_next_monitor_event) {
|
||||
// app->priv->skip_next_monitor_event = FALSE;
|
||||
// return;
|
||||
// }
|
||||
/* else: the file got changed but not by us, we'll
|
||||
* update our data from disk */
|
||||
}
|
||||
if (info.xdg_position < xdg_position) {
|
||||
/* we don't really care about this file, since we
|
||||
* already have something with a higher priority, or
|
||||
* we're going to write something in the user config
|
||||
* anyway.
|
||||
* Note: xdg_position >= 1 so it's a system dir */
|
||||
info.xdg_system_position = MIN (xdg_position, info.xdg_system_position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GKeyFile *keyfile;
|
||||
keyfile = g_key_file_new ();
|
||||
if (!g_key_file_load_from_file (keyfile, desktopFile.toStdString().c_str(), G_KEY_FILE_NONE, NULL)) {
|
||||
g_key_file_free (keyfile);
|
||||
return;
|
||||
}
|
||||
|
||||
bool hidden = gsp_key_file_get_boolean (keyfile, G_KEY_FILE_DESKTOP_KEY_HIDDEN, FALSE);
|
||||
bool no_display = gsp_key_file_get_boolean (keyfile,G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,FALSE);
|
||||
bool enabled = gsp_key_file_get_boolean (keyfile, KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED,TRUE);
|
||||
bool shown = gsp_key_file_get_shown (keyfile,_gsp_get_current_desktop ());
|
||||
|
||||
std::string formatted_result(make_string(gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_NAME)));
|
||||
QString name = QString::fromStdString(formatted_result);
|
||||
formatted_result = make_string(gsp_key_file_get_string (keyfile, G_KEY_FILE_DESKTOP_KEY_EXEC));
|
||||
QString exec = QString::fromStdString(formatted_result);
|
||||
formatted_result = make_string(gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_COMMENT));
|
||||
QString comment = QString::fromStdString(formatted_result);
|
||||
formatted_result = make_string(gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_ICON));
|
||||
QString icon = QString::fromStdString(formatted_result);
|
||||
if (name.isEmpty() || name.isNull())
|
||||
name = exec;
|
||||
|
||||
/*QSettings setting(desktopFile, QSettings::IniFormat);
|
||||
setting.setIniCodec("UTF-8");
|
||||
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();
|
||||
setting.endGroup();*/
|
||||
|
||||
//get description
|
||||
QString primary;
|
||||
|
@ -206,7 +524,6 @@ void StartupWorker::addStartupInfo(const QString &desktopFile)
|
|||
}
|
||||
QString description = QString("<b>%1</b>\n%2").arg(primary).arg(secondary);
|
||||
|
||||
StartupData info;
|
||||
info.basename = basename;
|
||||
info.path = desktopFile;
|
||||
info.hidden = hidden;
|
||||
|
@ -219,8 +536,18 @@ void StartupWorker::addStartupInfo(const QString &desktopFile)
|
|||
info.icon = icon;
|
||||
info.description = description;
|
||||
|
||||
if (xdg_position > 0) {
|
||||
info.xdg_system_position = xdg_position;
|
||||
}
|
||||
/* else we keep the old value (which is G_MAXUINT if it wasn't set) */
|
||||
info.xdg_position = xdg_position;
|
||||
info.old_system_path.clear();
|
||||
|
||||
//printf("hidden=%s\n", hidden ? "Yes" : "No");
|
||||
|
||||
m_startupInfoList[exec] = info;//append item
|
||||
|
||||
/*
|
||||
//show or hide
|
||||
if (!hidden && shown && !no_display) {
|
||||
//show
|
||||
|
@ -235,6 +562,7 @@ void StartupWorker::addStartupInfo(const QString &desktopFile)
|
|||
if (isExecContains(exec))
|
||||
m_startupInfoList.remove(exec);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool StartupWorker::isExecContains(const QString &exec)
|
||||
|
@ -251,3 +579,452 @@ StartupData StartupWorker::getStartupInfo(const QString &exec)
|
|||
{
|
||||
return m_startupInfoList.value(exec, StartupData());//nullptr
|
||||
}
|
||||
|
||||
void StartupWorker::updateEnable(const QString &exec, bool enabled)
|
||||
{
|
||||
// m_startupInfoList.value(exec).enabled = enabled;
|
||||
// m_startupInfoList.value(exec).setEnabled(enabled);
|
||||
if (m_startupInfoList.contains(exec)) {
|
||||
m_startupInfoList[exec].enabled = enabled;//m_startupInfoList[exec].setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void StartupWorker::updateSaveMask(const QString &exec, unsigned int save_mask)
|
||||
{
|
||||
if (m_startupInfoList.contains(exec)) {
|
||||
m_startupInfoList[exec].save_mask = save_mask;
|
||||
}
|
||||
}
|
||||
|
||||
void StartupWorker::updateXdgPosition(const QString &exec, unsigned int xdg_position)
|
||||
{
|
||||
if (m_startupInfoList.contains(exec)) {
|
||||
m_startupInfoList[exec].xdg_position = xdg_position;
|
||||
}
|
||||
}
|
||||
|
||||
void StartupWorker::updateXdgSystemPosition(const QString &exec, unsigned int xdg_system_position)
|
||||
{
|
||||
if (m_startupInfoList.contains(exec)) {
|
||||
m_startupInfoList[exec].xdg_system_position = xdg_system_position;
|
||||
}
|
||||
}
|
||||
|
||||
void StartupWorker::updateOldSystemPath(const QString &exec, QString old_system_path)
|
||||
{
|
||||
if (m_startupInfoList.contains(exec)) {
|
||||
m_startupInfoList[exec].old_system_path = old_system_path;
|
||||
}
|
||||
}
|
||||
|
||||
void StartupWorker::updatePath(const QString &exec, QString path)
|
||||
{
|
||||
if (m_startupInfoList.contains(exec)) {
|
||||
m_startupInfoList[exec].path = path;
|
||||
}
|
||||
}
|
||||
|
||||
void StartupWorker::_gsp_ensure_user_autostart_dir (void)
|
||||
{
|
||||
char *dir;
|
||||
dir = g_build_filename(g_get_user_config_dir(), "autostart", NULL);
|
||||
g_mkdir_with_parents(dir, S_IRWXU);
|
||||
printf("ensure dir=%s\n", dir);
|
||||
g_free(dir);
|
||||
|
||||
// QDir dir;
|
||||
// if(!dir.exists("aa")){
|
||||
// dir.mkdir("aa");
|
||||
// }
|
||||
|
||||
|
||||
/*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));
|
||||
QString dir = QString::fromStdString(formatted_result);
|
||||
//S_IRWXU 00700 权限,代表该文件所有者具有可读、可写及可执行的权限
|
||||
if (dir.endsWith("/"))
|
||||
g_mkdir_with_parents (dir + "autostart", S_IRWXU);//if (g_mkdir_with_parents (dir, 0755) == 0)
|
||||
else
|
||||
g_mkdir_with_parents (dir + "/autostart", S_IRWXU);*/
|
||||
}
|
||||
|
||||
void StartupWorker::_gsp_app_save_done_success (StartupData info)
|
||||
{
|
||||
info.save_mask = 0;
|
||||
this->updateSaveMask(info.exec, info.save_mask);
|
||||
if (!info.old_system_path.isEmpty()) {
|
||||
info.old_system_path.clear();
|
||||
this->updateOldSystemPath(info.exec, info.old_system_path);
|
||||
}
|
||||
}
|
||||
|
||||
bool StartupWorker::_gsp_app_user_equal_system (StartupData info, char **system_path)
|
||||
{
|
||||
QString system_dir;
|
||||
char *path;
|
||||
char *str;
|
||||
GKeyFile *keyfile;
|
||||
|
||||
system_dir = gsp_app_manager_get_dir(info.xdg_system_position);
|
||||
if (system_dir.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
path = g_build_filename(system_dir.toStdString().c_str(), info.basename.toStdString().c_str(), NULL);
|
||||
|
||||
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) != info.hidden ||
|
||||
gsp_key_file_get_boolean (keyfile,
|
||||
KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED,
|
||||
TRUE) != info.enabled ||
|
||||
gsp_key_file_get_shown (keyfile,
|
||||
_gsp_get_current_desktop ()) != info.shown) {
|
||||
g_free (path);
|
||||
g_key_file_free (keyfile);
|
||||
return false;
|
||||
}
|
||||
if (gsp_key_file_get_boolean (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
|
||||
FALSE) != info.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, info.name.toStdString().c_str())) {
|
||||
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, info.comment.toStdString().c_str())) {
|
||||
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, info.exec.toStdString().c_str())) {
|
||||
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, info.icon.toStdString().c_str())) {//info.icon.toStdString().data()
|
||||
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;
|
||||
}
|
||||
|
||||
/*bool StartupWorker::_gsp_app_user_equal_system (StartupData info, QString &system_path, QString locale)
|
||||
{
|
||||
QString system_dir;
|
||||
QString path;
|
||||
QString str;
|
||||
|
||||
qDebug() << "info.xdg_system_position="<<info.xdg_system_position;
|
||||
system_dir = gsp_app_manager_get_dir(info.xdg_system_position);
|
||||
if (system_dir.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
path = QString("%1/%2").arg(system_dir).arg(info.basename);
|
||||
qDebug() << "_gsp_app_user_equal_system path="<<path;
|
||||
|
||||
QSettings setting(path, QSettings::IniFormat);
|
||||
setting.setIniCodec("UTF-8");
|
||||
setting.beginGroup(KEY_FILE_DESKTOP_GROUP);
|
||||
|
||||
if (setting.value(KEY_FILE_DESKTOP_KEY_HIDDEN, false).toBool() != info.hidden
|
||||
|| setting.value(KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED, true).toBool() != info.enabled
|
||||
|| getShownFromDesktopFile(path, getCurrentDesktopEnvironment()) != info.shown) {
|
||||
setting.endGroup();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (setting.value(KEY_FILE_DESKTOP_KEY_NO_DISPLAY, false).toBool() != info.no_display) {
|
||||
setting.endGroup();
|
||||
return false;
|
||||
}
|
||||
|
||||
str = setting.value(QString("%1\[%2\]").arg(KEY_FILE_DESKTOP_KEY_NAME).arg(locale)).toString();
|
||||
if (QString::compare(str, info.name) != 0) {
|
||||
setting.endGroup();
|
||||
return false;
|
||||
}
|
||||
str = setting.value(QString("%1\[%2\]").arg(KEY_FILE_DESKTOP_KEY_COMMENT).arg(locale)).toString();
|
||||
if (QString::compare(str, info.comment) != 0) {
|
||||
setting.endGroup();
|
||||
return false;
|
||||
}
|
||||
|
||||
str = setting.value(KEY_FILE_DESKTOP_KEY_EXEC).toString();
|
||||
if (QString::compare(str, info.exec) != 0) {
|
||||
setting.endGroup();
|
||||
return false;
|
||||
}
|
||||
|
||||
str = setting.value(QString("%1\[%2\]").arg(KEY_FILE_DESKTOP_KEY_ICON).arg(locale)).toString();
|
||||
if (QString::compare(str, info.icon) != 0) {
|
||||
setting.endGroup();
|
||||
return false;
|
||||
}
|
||||
system_path = path;
|
||||
|
||||
setting.endGroup();
|
||||
|
||||
return true;
|
||||
}*/
|
||||
|
||||
//void StartupWorker::gsp_key_file_ensure_C_key(QString filename, QString key, QString locale)
|
||||
//{
|
||||
// QSettings setting(filename, QSettings::IniFormat);
|
||||
// setting.setIniCodec("UTF-8");
|
||||
// setting.beginGroup(KEY_FILE_DESKTOP_GROUP);
|
||||
// QString C_value;
|
||||
// /* Make sure we set the "C" locale strings to the terms we set here.
|
||||
// * This is so that if the user logs into another locale they get their
|
||||
// * own description there rather then empty. It is not the C locale
|
||||
// * however, but the user created this entry herself so it's OK */
|
||||
// C_value = setting.value(key).toString();
|
||||
// if (C_value.isEmpty() || C_value.isNull()) {
|
||||
// QString buffer = setting.value(QString("%1\[%2\]").arg(key).arg(locale)).toString();//g_key_file_get_locale_string
|
||||
// if (!buffer.isEmpty()) {
|
||||
// setting.setValue(key, buffer);
|
||||
// }
|
||||
// }
|
||||
// setting.endGroup();
|
||||
// setting.sync();
|
||||
//}
|
||||
|
||||
|
||||
|
||||
bool StartupWorker::_gsp_app_save(StartupData info)
|
||||
{
|
||||
char *use_path;
|
||||
GKeyFile *keyfile;
|
||||
GError *error;
|
||||
|
||||
/* 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 (info, &use_path)) {
|
||||
// if (g_file_test(info.path.toStdString().c_str(), G_FILE_TEST_EXISTS)) {
|
||||
// g_remove(info.path.toStdString().c_str());
|
||||
// }
|
||||
QFile file(info.path);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
std::string formatted_result(make_string(g_strdup(use_path)));
|
||||
info.path = QString::fromStdString(formatted_result);
|
||||
info.xdg_position = info.xdg_system_position;
|
||||
_gsp_app_save_done_success(info);
|
||||
return false;
|
||||
}
|
||||
if (!info.old_system_path.isEmpty())
|
||||
use_path = g_strdup(info.old_system_path.toStdString().c_str());
|
||||
else
|
||||
use_path = g_strdup(info.path.toStdString().c_str());
|
||||
|
||||
printf("normal use_path=%s", use_path);
|
||||
|
||||
keyfile = g_key_file_new ();
|
||||
|
||||
error = NULL;
|
||||
GKeyFileFlags flags;
|
||||
flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
|
||||
g_key_file_load_from_file (keyfile, use_path, flags, &error);
|
||||
g_free(use_path);
|
||||
|
||||
if (error) {
|
||||
g_error_free (error);
|
||||
gsp_key_file_populate (keyfile);
|
||||
}
|
||||
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_HIDDEN) {
|
||||
gsp_key_file_set_boolean (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_HIDDEN,
|
||||
info.hidden);
|
||||
}
|
||||
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_NO_DISPLAY) {
|
||||
gsp_key_file_set_boolean (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
|
||||
info.no_display);
|
||||
}
|
||||
|
||||
if (info.save_mask & SAVE_MASK_ENABLED) {
|
||||
gsp_key_file_set_boolean (keyfile,
|
||||
KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED,
|
||||
info.enabled);
|
||||
}
|
||||
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_NAME) {
|
||||
gsp_key_file_set_locale_string (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_NAME,
|
||||
info.name.toStdString().c_str());
|
||||
gsp_key_file_ensure_C_key (keyfile, G_KEY_FILE_DESKTOP_KEY_NAME);
|
||||
}
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_COMMENT) {
|
||||
gsp_key_file_set_locale_string (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_COMMENT,
|
||||
info.comment.toStdString().c_str());
|
||||
gsp_key_file_ensure_C_key (keyfile, G_KEY_FILE_DESKTOP_KEY_COMMENT);
|
||||
}
|
||||
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_EXEC) {
|
||||
gsp_key_file_set_string (keyfile,
|
||||
G_KEY_FILE_DESKTOP_KEY_EXEC,
|
||||
info.exec.toStdString().c_str());
|
||||
}
|
||||
|
||||
_gsp_ensure_user_autostart_dir ();
|
||||
if (gsp_key_file_to_file (keyfile, info.path.toStdString().c_str(), NULL)) {
|
||||
_gsp_app_save_done_success(info);
|
||||
} else {
|
||||
qDebug() << QString("Could not save %1 file").arg(info.path);
|
||||
}
|
||||
|
||||
g_key_file_free (keyfile);
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
QString use_path;
|
||||
|
||||
QString locale = QLocale::system().name();
|
||||
// qDebug() << "locale="<<locale;
|
||||
|
||||
//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(info, use_path, locale)) {
|
||||
qDebug() << "system use_path="<<use_path;
|
||||
QFile file(info.path);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
info.path = use_path;
|
||||
this->updatePath(info.exec, info.path);
|
||||
info.xdg_position = info.xdg_system_position;
|
||||
this->updateXdgPosition(info.exec, info.xdg_position);
|
||||
_gsp_app_save_done_success(info);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!info.old_system_path.isEmpty())
|
||||
use_path = info.old_system_path;
|
||||
else
|
||||
use_path = info.path;
|
||||
|
||||
qDebug() << "normal use_path="<<use_path;
|
||||
|
||||
// const char *locale;
|
||||
// const char * const *langs_pointer;
|
||||
// int i;
|
||||
// locale = NULL;
|
||||
// langs_pointer = g_get_language_names ();
|
||||
// for (i = 0; langs_pointer[i] != NULL; i++) {
|
||||
// printf("langs_pointer[i]=%s\n", langs_pointer[i]);
|
||||
// //find first without encoding
|
||||
// if (strchr (langs_pointer[i], '.') == NULL) {
|
||||
// locale = langs_pointer[i];
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (locale != NULL) {
|
||||
// printf("locale=%s\n", locale);//locale=zh_CN
|
||||
// }
|
||||
|
||||
//if read error:set KEY_FILE_DESKTOP_KEY_TYPE "Application" and set KEY_FILE_DESKTOP_KEY_EXEC "/bin/false"
|
||||
QSettings setting(use_path, QSettings::IniFormat);
|
||||
setting.setIniCodec("UTF-8");
|
||||
setting.beginGroup(KEY_FILE_DESKTOP_GROUP);
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_HIDDEN) {
|
||||
setting.setValue(KEY_FILE_DESKTOP_KEY_HIDDEN, info.hidden);
|
||||
}
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_NO_DISPLAY) {
|
||||
setting.setValue(KEY_FILE_DESKTOP_KEY_NO_DISPLAY, info.no_display);
|
||||
}
|
||||
if (info.save_mask & SAVE_MASK_ENABLED) {
|
||||
setting.setValue(KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED, info.enabled);
|
||||
}
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_NAME) {
|
||||
setting.setValue(QString("%1\[%2\]").arg(KEY_FILE_DESKTOP_KEY_NAME).arg(locale), info.name);
|
||||
// gsp_key_file_ensure_C_key(use_path, KEY_FILE_DESKTOP_KEY_NAME, locale);
|
||||
}
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_COMMENT) {
|
||||
setting.setValue(QString("%1\[%2\]").arg(KEY_FILE_DESKTOP_KEY_COMMENT).arg(locale), info.comment);
|
||||
// gsp_key_file_ensure_C_key(use_path, KEY_FILE_DESKTOP_KEY_NAME, locale);
|
||||
}
|
||||
if (info.save_mask & GSP_ASP_SAVE_MASK_EXEC) {
|
||||
setting.setValue(KEY_FILE_DESKTOP_KEY_EXEC, info.exec);
|
||||
}
|
||||
_gsp_ensure_user_autostart_dir();
|
||||
|
||||
setting.endGroup();
|
||||
setting.sync();
|
||||
_gsp_app_save_done_success(info);
|
||||
|
||||
return false;*/
|
||||
}
|
||||
|
||||
|
||||
void StartupWorker::_gsp_app_queue_save(StartupData info)
|
||||
{
|
||||
/* 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;
|
||||
this->updateXdgPosition(info.exec, info.xdg_position);
|
||||
if (info.old_system_path.isEmpty()) {
|
||||
info.old_system_path = info.path;
|
||||
this->updateOldSystemPath(info.exec, info.old_system_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 */
|
||||
}
|
||||
const gchar *config_dir = g_get_user_config_dir();
|
||||
std::string formatted_result(make_string(g_strdup(config_dir)));
|
||||
QString tmpPath = QString::fromStdString(formatted_result);
|
||||
if (tmpPath.endsWith("/"))
|
||||
info.path = QString("%1/autostart/%2").arg(tmpPath).arg(info.basename);
|
||||
else
|
||||
info.path = QString("%1/autostart/%2").arg(tmpPath).arg(info.basename);
|
||||
this->updatePath(info.exec, info.path);
|
||||
}
|
||||
_gsp_app_save(info);
|
||||
}
|
||||
|
|
|
@ -34,10 +34,33 @@
|
|||
#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_TRY_EXEC "TryExec"
|
||||
#define KEY_FILE_DESKTOP_KEY_COMMENT "Comment"
|
||||
#define KEY_FILE_DESKTOP_KEY_ICON "Icon"
|
||||
#define KEY_FILE_DESKTOP_KEY_TYPE "Type"
|
||||
#define KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
|
||||
#define KEY_FILE_DESKTOP_TYPE_LINK "Link"
|
||||
#define KEY_FILE_DESKTOP_KEY_URL "URL"
|
||||
#define KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"
|
||||
#define KEY_FILE_DESKTOP_KEY_CATEGORIES "Categories"
|
||||
#define KEY_FILE_DESKTOP_KEY_MIME_TYPE "MimeType"
|
||||
#define KEY_FILE_DESKTOP_KEY_TERMINAL "Terminal"
|
||||
#define KEY_FILE_DESKTOP_TYPE_DIRECTORY "Directory"
|
||||
|
||||
|
||||
#define GSP_ASP_SAVE_MASK_HIDDEN 0x0001
|
||||
#define SAVE_MASK_ENABLED 0x0002
|
||||
#define GSP_ASP_SAVE_MASK_NAME 0x0004
|
||||
#define GSP_ASP_SAVE_MASK_EXEC 0x0008
|
||||
#define GSP_ASP_SAVE_MASK_COMMENT 0x0010
|
||||
#define GSP_ASP_SAVE_MASK_NO_DISPLAY 0x0020
|
||||
#define GSP_ASP_SAVE_MASK_ALL 0xffff
|
||||
|
||||
typedef struct {
|
||||
QString dir;
|
||||
int index;
|
||||
// GFileMonitor *monitor;
|
||||
} GspXdgDir;
|
||||
|
||||
class StartupWorker : public QObject
|
||||
{
|
||||
|
@ -46,13 +69,36 @@ class StartupWorker : public QObject
|
|||
public:
|
||||
explicit StartupWorker(QObject *parent = 0);
|
||||
~StartupWorker();
|
||||
void addStartupInfo(const QString &desktopFile);
|
||||
void newStartupInfo(const QString &desktopFile, unsigned int xdg_position);
|
||||
bool isExecContains(const QString &exec);
|
||||
QList<StartupData> getStartupInfoList() const;
|
||||
StartupData getStartupInfo(const QString &exec);
|
||||
|
||||
// void gsp_key_file_ensure_C_key(QString filename, QString key, QString locale);
|
||||
|
||||
void updateEnable(const QString &exec, bool enabled);
|
||||
void updateSaveMask(const QString &exec, unsigned int save_mask);
|
||||
void updateXdgPosition(const QString &exec, unsigned int xdg_position);
|
||||
void updateXdgSystemPosition(const QString &exec, unsigned int xdg_system_position);
|
||||
void updateOldSystemPath(const QString &exec, QString old_system_path);
|
||||
void updatePath(const QString &exec, QString path);
|
||||
|
||||
void AddDirWithIndex(GspXdgDir dir);
|
||||
int getDirIndex(QString dir);
|
||||
QString gsp_app_manager_get_dir(unsigned int index);
|
||||
QList<GspXdgDir> getAllDirs() { return dirs; }
|
||||
|
||||
void _gsp_ensure_user_autostart_dir(void);
|
||||
void _gsp_app_save_done_success (StartupData info);
|
||||
// bool _gsp_app_user_equal_system (StartupData info, QString &system_path, QString locale);
|
||||
bool _gsp_app_user_equal_system (StartupData info, char **system_path);
|
||||
bool _gsp_app_save(StartupData info);
|
||||
void _gsp_app_queue_save(StartupData info);
|
||||
StartupData gsp_app_manager_find_app_with_basename(QString &basename);
|
||||
|
||||
private:
|
||||
QMap<QString, StartupData> m_startupInfoList;
|
||||
QList<GspXdgDir> dirs;
|
||||
};
|
||||
|
||||
#endif // STARTUPWORKER_H
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
std::string make_string(char *c_str)
|
||||
{
|
||||
if (!c_str) {
|
||||
return string();
|
||||
}
|
||||
string s(c_str);
|
||||
g_free(c_str);
|
||||
return s;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
using std::string;
|
||||
|
||||
std::string make_string(char *c_str);
|
Loading…
Reference in New Issue