From aa25cb26051d2d6210fc28b072ce823ea7b55280 Mon Sep 17 00:00:00 2001 From: cetc32-ck Date: Thu, 3 Mar 2022 14:58:04 +0800 Subject: [PATCH] ukui settings daemon master improve disk monitoring1 --- plugins/housekeeping/housekeeping-manager.cpp | 17 ++-- plugins/housekeeping/housekeeping-manager.h | 6 +- plugins/housekeeping/housekeeping-plugin.cpp | 46 ++++++++-- plugins/housekeeping/housekeeping-plugin.h | 1 + plugins/housekeeping/ldsm-trash-empty.cpp | 4 +- plugins/housekeeping/usd-disk-space.cpp | 89 +++++++++++-------- plugins/housekeeping/usd-disk-space.h | 11 ++- plugins/housekeeping/usd-ldsm-dialog.cpp | 59 ++++++------ plugins/housekeeping/usd-ldsm-dialog.h | 2 +- plugins/xsettings/ukui-xsettings-manager.cpp | 9 +- 10 files changed, 156 insertions(+), 88 deletions(-) diff --git a/plugins/housekeeping/housekeeping-manager.cpp b/plugins/housekeeping/housekeeping-manager.cpp index 34aba913..9697aff3 100644 --- a/plugins/housekeeping/housekeeping-manager.cpp +++ b/plugins/housekeeping/housekeeping-manager.cpp @@ -59,9 +59,14 @@ HousekeepingManager::HousekeepingManager() mDisk = new DIskSpace(); settings = new QGSettings(THUMB_CACHE_SCHEMA); long_term_handler = new QTimer(this); - connect(long_term_handler, SIGNAL(timeout()), this, SLOT(do_cleanup())); + short_term_handler = new QTimer(this); - connect(short_term_handler, SIGNAL(timeout()), this, SLOT(do_cleanup_once())); + + connect(long_term_handler, &QTimer::timeout, + this, &HousekeepingManager::do_cleanup); + connect(short_term_handler, &QTimer::timeout, + this, &HousekeepingManager::do_cleanup_once); + } /* @@ -231,10 +236,10 @@ bool HousekeepingManager::HousekeepingManagerStart() { mDisk->UsdLdsmSetup(false); - connect (settings, - SIGNAL(changed(QString)), - this, - SLOT(settings_changed_callback(QString))); + connect (settings, &QGSettings::changed, + this,&HousekeepingManager::settings_changed_callback); + + /* Clean once, a few minutes after start-up */ do_cleanup_soon(); diff --git a/plugins/housekeeping/housekeeping-manager.h b/plugins/housekeeping/housekeeping-manager.h index 7ab685a5..5f337dd6 100644 --- a/plugins/housekeeping/housekeeping-manager.h +++ b/plugins/housekeeping/housekeeping-manager.h @@ -21,7 +21,7 @@ #define HOUSEKEEPINGMANAGER_H #include -#include +#include #include @@ -33,7 +33,7 @@ class HousekeepingManager : public QObject { Q_OBJECT -// private: + public: HousekeepingManager(); HousekeepingManager(HousekeepingManager&)=delete; @@ -42,7 +42,7 @@ class HousekeepingManager : public QObject bool HousekeepingManagerStart(); void HousekeepingManagerStop(); -public Q_SLOTS: +public: void settings_changed_callback(QString); void do_cleanup_soon(); void purge_thumbnail_cache (); diff --git a/plugins/housekeeping/housekeeping-plugin.cpp b/plugins/housekeeping/housekeeping-plugin.cpp index 2e5ad82b..6454d213 100644 --- a/plugins/housekeeping/housekeeping-plugin.cpp +++ b/plugins/housekeeping/housekeeping-plugin.cpp @@ -19,16 +19,45 @@ #include #include +#include #include "housekeeping-plugin.h" #include "clib-syslog.h" PluginInterface *HousekeepingPlugin::mInstance=nullptr; +QString getCurrentUserName() +{ + QString name; + if (name.isEmpty()){ + QStringList envList = QProcess::systemEnvironment(); + for(const QString& env : envList){ + if(env.startsWith("USERNAME")){ + QStringList strList = env.split('='); + if(strList.size() > 2){ + name = strList[1]; + } + } + } + } + if(!name.isEmpty()) + return name; + QProcess process; + process.start("whoami", QStringList()); + process.waitForFinished(); + name = QString::fromLocal8Bit(process.readAllStandardOutput()).trimmed(); + return name.isEmpty() ? QString("User") : name; +} + + HousekeepingPlugin::HousekeepingPlugin() { - mHouseManager = new HousekeepingManager(); - if(!mHouseManager) - syslog(LOG_ERR,"Unable to start Housekeeping Manager!"); + userName = getCurrentUserName(); + if(userName.compare("lightdm") != 0){ + mHouseManager = new HousekeepingManager(); + if(!mHouseManager) + syslog(LOG_ERR,"Unable to start Housekeeping Manager!"); + } + } HousekeepingPlugin::~HousekeepingPlugin() @@ -62,7 +91,11 @@ void HousekeepingPlugin::activate() { if(isTrialMode()) return; - mHouseManager->HousekeepingManagerStart(); + + if(userName.compare("lightdm") != 0){ + mHouseManager->HousekeepingManagerStart(); + } + } PluginInterface *HousekeepingPlugin::getInstance() @@ -76,7 +109,10 @@ void HousekeepingPlugin::deactivate() { if(isTrialMode()) return; - mHouseManager->HousekeepingManagerStop(); + + if(mHouseManager) + mHouseManager->HousekeepingManagerStop(); + } PluginInterface *createSettingsPlugin() diff --git a/plugins/housekeeping/housekeeping-plugin.h b/plugins/housekeeping/housekeeping-plugin.h index a71dc119..31834fdf 100644 --- a/plugins/housekeeping/housekeeping-plugin.h +++ b/plugins/housekeeping/housekeeping-plugin.h @@ -36,6 +36,7 @@ class HousekeepingPlugin : public PluginInterface HousekeepingPlugin(HousekeepingPlugin&)=delete; private: + QString userName; HousekeepingManager *mHouseManager; static PluginInterface *mInstance; diff --git a/plugins/housekeeping/ldsm-trash-empty.cpp b/plugins/housekeeping/ldsm-trash-empty.cpp index 82bb2e70..ad20110c 100644 --- a/plugins/housekeeping/ldsm-trash-empty.cpp +++ b/plugins/housekeeping/ldsm-trash-empty.cpp @@ -58,7 +58,9 @@ void LdsmTrashEmpty::windowLayoutInit() setWindowFlags(flags); setFixedSize(650,180); setWindowTitle(tr("Emptying the trash")); - setWindowIcon(QIcon("/new/prefix1/warning.png")); + //setWindowIcon(QIcon("/new/prefix1/warning.png")); + setWindowIcon(QIcon::fromTheme("user-trash-full")); + int dialog_width=width(); int dialog_height=height(); int rect_width=desk_rect.width(); diff --git a/plugins/housekeeping/usd-disk-space.cpp b/plugins/housekeeping/usd-disk-space.cpp index 8e6263e0..92d4792e 100644 --- a/plugins/housekeeping/usd-disk-space.cpp +++ b/plugins/housekeeping/usd-disk-space.cpp @@ -42,26 +42,31 @@ DIskSpace::DIskSpace() ldsm_timeout_cb = new QTimer(); trash_empty=new LdsmTrashEmpty(); - connect(ldsm_timeout_cb, SIGNAL(timeout()), this, SLOT(ldsm_check_all_mounts())); + ldsm_notified_hash=NULL; + ldsm_monitor = NULL; + free_percent_notify = 0.05; + free_percent_notify_again = 0.01; + free_size_gb_no_notify = 2; + min_notify_period = 10; + ignore_paths = NULL; + done = FALSE; + + connect(ldsm_timeout_cb, &QTimer::timeout, + this, &DIskSpace::ldsm_check_all_mounts); + ldsm_timeout_cb->start(); - this->ldsm_notified_hash=NULL; - this->ldsm_monitor = NULL; - this->free_percent_notify = 0.05; - this->free_percent_notify_again = 0.01; - this->free_size_gb_no_notify = 2; - this->min_notify_period = 10; - this->ignore_paths = NULL; - this->done = FALSE; + if (QGSettings::isSchemaInstalled(SETTINGS_HOUSEKEEPING_SCHEMA)) { settings = new QGSettings(SETTINGS_HOUSEKEEPING_SCHEMA); } - this->dialog = NULL; + this->dialog = nullptr; } DIskSpace::~DIskSpace() { delete trash_empty; + delete settings; } static gint @@ -94,16 +99,17 @@ void DIskSpace::usdLdsmGetConfig() free_percent_notify =settings->get(SETTINGS_FREE_PC_NOTIFY_KEY).toDouble(); if (free_percent_notify >= 1 || free_percent_notify < 0) { /* FIXME define min and max in gschema! */ - g_warning ("Invalid configuration of free_percent_notify: %f\n" \ - "Using sensible default", free_percent_notify); + qWarning ("housekeeping: Invalid configuration of free_percent_notify: %f\n" \ + "Using sensible default", free_percent_notify); + free_percent_notify = 0.05; } // 取得第二次提醒的百分比时机 free_percent_notify_again = settings->get(SETTINGS_FREE_PC_NOTIFY_AGAIN_KEY).toDouble(); if (free_percent_notify_again >= 1 || free_percent_notify_again < 0) { /* FIXME define min and max in gschema! */ - g_warning ("Invalid configuration of free_percent_notify_again: %f\n" \ - "Using sensible default\n", free_percent_notify_again); + qWarning ("housekeeping: Invalid configuration of free_percent_notify_again: %f\n" \ + "Using sensible default\n", free_percent_notify_again); free_percent_notify_again = 0.01; } @@ -117,14 +123,6 @@ void DIskSpace::usdLdsmGetConfig() g_slist_free (ignore_paths); ignore_paths = NULL; } - - // 取得清理忽略的目录 - //settings_list =settings->getStrv(SETTINGS_IGNORE_PATHS); - QVariantList ignoreList = settings->choices(SETTINGS_IGNORE_PATHS); - QVariantList::const_iterator it; - for (it = ignoreList.constBegin(); it != ignoreList.constEnd(); ++it) { - m_notified_hash.remove((*it).toString().toLatin1().data()); - } } static void @@ -173,7 +171,7 @@ bool DIskSpace::ldsm_mount_should_ignore (GUnixMountEntry *mount) const gchar *fs, *device, *path; path = g_unix_mount_get_mount_path (mount); - if (DIskSpace::ldsm_mount_is_user_ignore (path)) + if (ldsm_mount_is_user_ignore (path)) return TRUE; /* This is borrowed from GLib and used as a way to determine @@ -399,30 +397,30 @@ bool DIskSpace::ldsm_notify_for_mount (LdsmMountInfo *mount, response = dialog->exec(); delete dialog; - dialog = NULL; + dialog = nullptr; switch (response) { case GTK_RESPONSE_CANCEL: - retval = FALSE; + retval = false; break; case LDSM_DIALOG_RESPONSE_ANALYZE: - retval = FALSE; + retval = false; ldsm_analyze_path (path); break; case LDSM_DIALOG_RESPONSE_EMPTY_TRASH: - retval = FALSE; + retval = false; trash_empty->usdLdsmTrashEmpty();//调清空回收站dialog break; case GTK_RESPONSE_NONE: case GTK_RESPONSE_DELETE_EVENT: - retval = TRUE; + retval = true; break; case LDSM_DIALOG_IGNORE: - retval = TRUE; + retval = true; break; default: //g_assert_not_reached (); - retval = FALSE; + retval = false; } free (path); return retval; @@ -509,6 +507,18 @@ void DIskSpace::ldsm_maybe_warn_mounts (GList *mounts, } } +bool DIskSpace::ldsmGetIgnorePath(const gchar *path) +{ + // 取得清理忽略的目录 + QStringList ignoreList = settings->get(SETTINGS_IGNORE_PATHS).toStringList(); + for (QString it : ignoreList) { + if (it.compare(path) == 0) + return true; + } + return false; +} + + bool DIskSpace::ldsm_check_all_mounts () { GList *mounts; @@ -547,8 +557,15 @@ bool DIskSpace::ldsm_check_all_mounts () path = g_unix_mount_get_mount_path (mount); if (g_strcmp0 (path, "/boot/efi") == 0 || - g_strcmp0 (path, "/boot") == 0 ) + g_strcmp0 (path, "/boot") == 0 ){ + ldsm_free_mount_info (mount_info); continue; + } + + if (ldsmGetIgnorePath(path)){ + ldsm_free_mount_info (mount_info); + continue; + } if (g_unix_mount_is_readonly (mount)) { ldsm_free_mount_info (mount_info); @@ -620,7 +637,8 @@ void DIskSpace::UsdLdsmSetup(bool check_now) //return; } usdLdsmGetConfig(); - connect(settings,SIGNAL(changed(QString)),this,SLOT(usdLdsmUpdateConfig(QString))); + connect(settings, &QGSettings::changed, + this, &DIskSpace::usdLdsmUpdateConfig); #if GLIB_CHECK_VERSION (2, 44, 0) ldsm_monitor = g_unix_mount_monitor_get (); #else @@ -655,12 +673,7 @@ void DIskSpace::UsdLdsmClean() if (settings) { g_object_unref (settings); } - /* - if (dialog) { - delete dialog; - dialog = NULL; - } -*/ + if (ignore_paths) { g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); g_slist_free (ignore_paths); diff --git a/plugins/housekeeping/usd-disk-space.h b/plugins/housekeeping/usd-disk-space.h index 1707969f..e6b8a074 100644 --- a/plugins/housekeeping/usd-disk-space.h +++ b/plugins/housekeeping/usd-disk-space.h @@ -20,9 +20,10 @@ #define DISKSPACE_H #include -//#include -#include +#include +#include +#include "usd-ldsm-dialog.h" #include "config.h" #include @@ -37,10 +38,8 @@ #include #include -#include "usd-ldsm-dialog.h" #include -class QGSettings; typedef struct { GUnixMountEntry *mount; @@ -68,9 +67,9 @@ class DIskSpace : public QObject bool other_usable_volumes); static void ldsm_mounts_changed (GObject *monitor,gpointer data,DIskSpace *disk); -public Q_SLOTS: - void usdLdsmUpdateConfig(QString); + bool ldsmGetIgnorePath(const gchar *path); bool ldsm_check_all_mounts(); + void usdLdsmUpdateConfig(QString); private: void cleanNotifyHash(); diff --git a/plugins/housekeeping/usd-ldsm-dialog.cpp b/plugins/housekeeping/usd-ldsm-dialog.cpp index 661af664..af7d19d1 100644 --- a/plugins/housekeeping/usd-ldsm-dialog.cpp +++ b/plugins/housekeeping/usd-ldsm-dialog.cpp @@ -83,6 +83,7 @@ void LdsmDialog::windowLayoutInit(bool display_baobab) flags |=Qt::WindowCloseButtonHint; setWindowFlags(flags); setFixedSize(660,210); + setWindowIcon(QIcon::fromTheme("dialog-warning")); int dialog_width=width(); int dialog_height=height(); int rect_width=desk_rect.width(); @@ -120,12 +121,12 @@ void LdsmDialog::windowLayoutInit(bool display_baobab) ignore_button->setText(tr("Ignore")); if(this->has_trash){ - trash_empty=new QPushButton(this); + trash_empty = new QPushButton(this); trash_empty->setGeometry(dialog_width-215,dialog_height-35,100,25); trash_empty->setText(tr("Empty Trash")); } if(display_baobab){ - analyze_button=new QPushButton(this); + analyze_button = new QPushButton(this); analyze_button->setText(tr("Examine")); if(this->has_trash) analyze_button->setGeometry(dialog_width-320,dialog_height-35,100,25); @@ -176,21 +177,24 @@ QString LdsmDialog::getCheckButtonText() void LdsmDialog::allConnectEvent(bool display_baobab) { - connect(ignore_check_button,SIGNAL(stateChanged(int)), - this,SLOT(checkButtonClicked(int))); - connect(ignore_button,SIGNAL(clicked()), - this,SLOT(checkButtonIgnore())); + connect(ignore_check_button, &QCheckBox::stateChanged, + this, &LdsmDialog::checkButtonClicked); + + connect(ignore_button, &QPushButton::clicked, + this, &LdsmDialog::checkButtonIgnore); + if(has_trash) - connect(trash_empty,SIGNAL(clicked()), - this,SLOT(checkButtonTrashEmpty())); + connect(trash_empty, &QPushButton::clicked, + this, &LdsmDialog::checkButtonTrashEmpty); + if(display_baobab) - connect(analyze_button,SIGNAL(clicked()), - this,SLOT(checkButtonAnalyze())); + connect(analyze_button, &QPushButton::clicked, + this, &LdsmDialog::checkButtonAnalyze); - if(this->sender() == this->ignore_button) - qDebug()<<"Ignore button pressed!"<* ignore_paths; bool ignore,updated; int i; QList::iterator l; - QString paths_data; - ignore_paths=new QList(); - settings=new QGSettings(SETTINGS_SCHEMA); + + ignore_paths =new QList(); + settings = new QGSettings(SETTINGS_SCHEMA); //get contents from "ignore-paths" key - ignore_list.append( settings->get(SETTINGS_IGNORE_PATHS).toString() ); + if (!settings->get(SETTINGS_IGNORE_PATHS).toStringList().isEmpty()) + ignore_list.append(settings->get(SETTINGS_IGNORE_PATHS).toStringList()); - for(i=0;ipush_back(ignore_list.at(i)); + for(auto str: ignore_list){ + if(!str.isEmpty()) + ignore_paths->push_back(str); + } - ignore=state; - updated=update_ignore_paths(&ignore_paths,mount_path,ignore); + ignore = state; + updated = update_ignore_paths(&ignore_paths,mount_path,ignore); if(updated){ - for(l=ignore_paths->begin();l!=ignore_paths->end();++l) - paths_data.append(*l); + for(l = ignore_paths->begin(); l != ignore_paths->end(); ++l){ + ignoreStr.append(*l); + } //set latest contents to gsettings "ignore-paths" key - settings->set(SETTINGS_IGNORE_PATHS,QVariant::fromValue(paths_data)); + settings->set(SETTINGS_IGNORE_PATHS, QVariant::fromValue(ignoreStr)); } //free QList Memory if(ignore_paths){ - //qDeleteAll(*ignore_paths); ignore_paths->clear(); } delete settings; diff --git a/plugins/housekeeping/usd-ldsm-dialog.h b/plugins/housekeeping/usd-ldsm-dialog.h index 38a22f54..e2686de5 100644 --- a/plugins/housekeeping/usd-ldsm-dialog.h +++ b/plugins/housekeeping/usd-ldsm-dialog.h @@ -68,7 +68,7 @@ class LdsmDialog : public QDialog QString partition_name; QString mount_path; -public Q_SLOTS: +public: void checkButtonClicked(int); void checkButtonIgnore (); void checkButtonAnalyze (); diff --git a/plugins/xsettings/ukui-xsettings-manager.cpp b/plugins/xsettings/ukui-xsettings-manager.cpp index 6a8478f3..fee08434 100644 --- a/plugins/xsettings/ukui-xsettings-manager.cpp +++ b/plugins/xsettings/ukui-xsettings-manager.cpp @@ -439,13 +439,18 @@ bool ukuiXSettingsManager::start() int screenNum = QGuiApplication::screens().length(); for(int i = 0; i < screenNum; i++){ QScreen *screen = QGuiApplication::screens().at(i); - qDebug()<geometry(); + if (screen->geometry().width() <= 1920 && screen->geometry().height() <= 1080) state = true; - else + else { state = false; + break; + } } if (state){ + GSettings *mGsettings; + mGsettings = (GSettings *)g_hash_table_lookup(this->gsettings, MOUSE_SCHEMA); + g_settings_set_double (mGsettings, CURSOR_SIZE_KEY, 24); g_settings_set_double (gsettings, SCALING_FACTOR_KEY, 1.0); } }