Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ukui settings daemon master improve disk monitoring1 #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions plugins/housekeeping/housekeeping-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

/*
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions plugins/housekeeping/housekeeping-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define HOUSEKEEPINGMANAGER_H

#include <QObject>
#include <QGSettings>
#include <QGSettings/qgsettings.h>
#include <QApplication>


Expand All @@ -33,7 +33,7 @@
class HousekeepingManager : public QObject
{
Q_OBJECT
// private:

public:
HousekeepingManager();
HousekeepingManager(HousekeepingManager&)=delete;
Expand All @@ -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 ();
Expand Down
46 changes: 41 additions & 5 deletions plugins/housekeeping/housekeeping-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,45 @@

#include <QString>
#include <QFile>
#include <QProcess>
#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()
Expand Down Expand Up @@ -62,7 +91,11 @@ void HousekeepingPlugin::activate()
{
if(isTrialMode())
return;
mHouseManager->HousekeepingManagerStart();

if(userName.compare("lightdm") != 0){
mHouseManager->HousekeepingManagerStart();
}

}

PluginInterface *HousekeepingPlugin::getInstance()
Expand All @@ -76,7 +109,10 @@ void HousekeepingPlugin::deactivate()
{
if(isTrialMode())
return;
mHouseManager->HousekeepingManagerStop();

if(mHouseManager)
mHouseManager->HousekeepingManagerStop();

}

PluginInterface *createSettingsPlugin()
Expand Down
1 change: 1 addition & 0 deletions plugins/housekeeping/housekeeping-plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class HousekeepingPlugin : public PluginInterface
HousekeepingPlugin(HousekeepingPlugin&)=delete;

private:
QString userName;
HousekeepingManager *mHouseManager;
static PluginInterface *mInstance;

Expand Down
4 changes: 3 additions & 1 deletion plugins/housekeeping/ldsm-trash-empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
89 changes: 51 additions & 38 deletions plugins/housekeeping/usd-disk-space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions plugins/housekeeping/usd-disk-space.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#define DISKSPACE_H

#include <QObject>
//#include <QApplication>
#include <QGSettings>

#include <QApplication>
#include <QGSettings/qgsettings.h>
#include "usd-ldsm-dialog.h"
#include "config.h"

#include <sys/statvfs.h>
Expand All @@ -37,10 +38,8 @@
#include <gtk/gtk.h>

#include <ldsm-trash-empty.h>
#include "usd-ldsm-dialog.h"

#include <qhash.h>
class QGSettings;
typedef struct
{
GUnixMountEntry *mount;
Expand Down Expand Up @@ -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();
Expand Down
Loading