diff options
author | Michele Calgaro <[email protected]> | 2019-04-13 00:33:10 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2019-04-13 00:33:10 +0900 |
commit | 691c9204a1a6dcbce52d41e62a988044e48270d4 (patch) | |
tree | 34bb4442388b2649eaed235a395258e1211110f7 | |
parent | 48635e6343601457bb1ae1e1a489ebce81266fab (diff) | |
download | tdebase-691c9204a1a6dcbce52d41e62a988044e48270d4.tar.gz tdebase-691c9204a1a6dcbce52d41e62a988044e48270d4.zip |
Added TDE Control module for trash policy configuration.
Signed-off-by: Michele Calgaro <[email protected]>
-rw-r--r-- | konqueror/sidebar/trees/init/trash.desktop | 2 | ||||
-rw-r--r-- | tdeioslave/trash/CMakeLists.txt | 20 | ||||
-rw-r--r-- | tdeioslave/trash/Makefile.am | 10 | ||||
-rw-r--r-- | tdeioslave/trash/kcm_trash.cpp | 81 | ||||
-rw-r--r-- | tdeioslave/trash/kcm_trash.desktop | 24 | ||||
-rw-r--r-- | tdeioslave/trash/kcm_trash.h | 47 | ||||
-rw-r--r-- | tdeioslave/trash/ktrashpropsdlgplugin.cpp | 5 | ||||
-rw-r--r-- | tdeioslave/trash/ktrashpropsdlgplugin.desktop | 8 | ||||
-rw-r--r-- | tdeioslave/trash/ktrashpropsdlgplugin.h | 5 | ||||
-rw-r--r-- | tdeioslave/trash/ktrashpropswidget.cpp | 465 | ||||
-rw-r--r-- | tdeioslave/trash/ktrashpropswidget.h | 93 |
11 files changed, 748 insertions, 12 deletions
diff --git a/konqueror/sidebar/trees/init/trash.desktop b/konqueror/sidebar/trees/init/trash.desktop index 147638122..2c1b7500f 100644 --- a/konqueror/sidebar/trees/init/trash.desktop +++ b/konqueror/sidebar/trees/init/trash.desktop @@ -8,8 +8,10 @@ X-TDE-KonqSidebarModule=konqsidebar_tree Name=Trash Folder Name[cz]=Složka koše +Name[fr]=Dossier Corbeille Name[it]=Cartella Cestino Comment=This folder displays the contents of your Trash Bin Comment[cz]=Tato složka zobrazuje obsah vašeho koše +Comment[fr]=Ce dossier montre le contenu de votre corbeille Comment[it]=Questa cartella visualizza il contenuto del tuo Cestino diff --git a/tdeioslave/trash/CMakeLists.txt b/tdeioslave/trash/CMakeLists.txt index 1082b57af..2f1b184a9 100644 --- a/tdeioslave/trash/CMakeLists.txt +++ b/tdeioslave/trash/CMakeLists.txt @@ -26,19 +26,18 @@ link_directories( ##### other data ################################ install( FILES ktrashpropsdlgplugin.desktop trash.protocol DESTINATION ${SERVICES_INSTALL_DIR} ) +install( FILES kcm_trash.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) ##### trashcommon (static) ###################### - set( target trashcommon ) tde_add_library( ${target} STATIC_PIC AUTOMOC - SOURCES trashimpl.cpp discspaceutil.cpp + SOURCES trashimpl.cpp discspaceutil.cpp ktrashpropswidget.cpp ) ##### tdeio_trash (module) ######################## - set( target tdeio_trash ) tde_add_kpart( ${target} AUTOMOC @@ -47,8 +46,18 @@ tde_add_kpart( ${target} AUTOMOC DESTINATION ${PLUGIN_INSTALL_DIR} ) -##### ktrashpropsdlgplugin (module) ######################## +##### kcm_trash (module) ######################## +set( target kcm_trash ) + +tde_add_kpart( ${target} AUTOMOC + SOURCES kcm_trash.cpp + LINK trashcommon-static tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### ktrashpropsdlgplugin (module) ######################## set( target ktrashpropsdlgplugin ) tde_add_kpart( ${target} AUTOMOC @@ -57,8 +66,8 @@ tde_add_kpart( ${target} AUTOMOC DESTINATION ${PLUGIN_INSTALL_DIR} ) -##### ktrash (executable) ####################### +##### ktrash (executable) ####################### set( target ktrash ) tde_add_executable( ${target} @@ -67,6 +76,7 @@ tde_add_executable( ${target} DESTINATION ${BIN_INSTALL_DIR} ) + ##### testtrash (executable) ####################### tde_add_executable( testtrash SOURCES testtrash.cpp AUTOMOC diff --git a/tdeioslave/trash/Makefile.am b/tdeioslave/trash/Makefile.am index 170701c3f..cee2825a1 100644 --- a/tdeioslave/trash/Makefile.am +++ b/tdeioslave/trash/Makefile.am @@ -3,12 +3,16 @@ METASOURCES = AUTO SUBDIRS = . tdefile-plugin -kde_module_LTLIBRARIES = tdeio_trash.la ktrashpropsdlgplugin.la +kde_module_LTLIBRARIES = tdeio_trash.la kcm_trash ktrashpropsdlgplugin.la tdeio_trash_la_SOURCES = tdeio_trash.cpp tdeio_trash_la_LIBADD = libtrashcommon.la $(LIB_TDEIO) tdeio_trash_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined +kcm_trash_la_SOURCES = kcm_trash.cpp +kcm_trash_la_LIBADD = libtrashcommon.la $(LIB_TDEIO) +kcm_trash_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined + bin_PROGRAMS = ktrash ktrash_SOURCES = ktrash.cpp ktrash_LDADD = $(LIB_TDEIO) @@ -17,7 +21,7 @@ ktrash_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) kde_services_DATA = trash.protocol noinst_LTLIBRARIES = libtrashcommon.la -libtrashcommon_la_SOURCES = trashimpl.cpp discspaceutil.cpp +libtrashcommon_la_SOURCES = trashimpl.cpp discspaceutil.cpp ktrashpropswidget.cpp check_PROGRAMS = testtrash testtrash_SOURCES = testtrash.cpp @@ -38,3 +42,5 @@ ktrashpropsdlgplugin_la_LIBADD = $(LIB_TDEIO) services_DATA = ktrashpropsdlgplugin.desktop servicesdir = $(kde_servicesdir) + +xdg_apps_DATA = kcm_trash.desktop diff --git a/tdeioslave/trash/kcm_trash.cpp b/tdeioslave/trash/kcm_trash.cpp new file mode 100644 index 000000000..abff4f612 --- /dev/null +++ b/tdeioslave/trash/kcm_trash.cpp @@ -0,0 +1,81 @@ +/* + This file is part of the TDE Project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kcm_trash.h" +#include "ktrashpropswidget.h" + +#include <tqlayout.h> +#include <tqtabwidget.h> +#include <tdelocale.h> +#include <tdeglobal.h> +#include <tdeaboutdata.h> +#include <kdialog.h> + + +extern "C" +{ + KDE_EXPORT TDECModule *create_trash(TQWidget *parent, const char *) + { + return new TrashModule(parent, "trash"); + } +} + + +TrashModule::TrashModule(TQWidget *parent, const char *name) + : TDECModule(parent, name) +{ + TDEAboutData * about = new TDEAboutData("trash", + I18N_NOOP("Trash"), "1", + I18N_NOOP("Trash Control Panel Module"), + TDEAboutData::License_GPL_V2, + I18N_NOOP("(c) 2019 Michele Calgaro")); + setAboutData( about ); + TDEGlobal::locale()->insertCatalogue("trash"); + + tab = new TQTabWidget(this); + + policyWidget = new KTrashPropsWidget(this); + tab->addTab(policyWidget, i18n("Trash Polic&y")); + connect(policyWidget, TQT_SIGNAL(changed(bool)), TQT_SIGNAL(changed(bool))); + + TQVBoxLayout *top = new TQVBoxLayout(this); + top->addWidget(tab); +} + +void TrashModule::load() +{ + policyWidget->load(); +} + +void TrashModule::save() +{ + policyWidget->save(); +} + +void TrashModule::defaults() +{ + policyWidget->setDefaultValues(); +} + +TQString TrashModule::quickHelp() const +{ + return i18n("<h1>Trash</h1> Here you can choose the settings " + "for your Trash Bin size and clean up policy. "); +} + +#include "kcm_trash.moc" diff --git a/tdeioslave/trash/kcm_trash.desktop b/tdeioslave/trash/kcm_trash.desktop new file mode 100644 index 000000000..83b70c920 --- /dev/null +++ b/tdeioslave/trash/kcm_trash.desktop @@ -0,0 +1,24 @@ +[Desktop Entry] +Exec=tdecmshell kcm_trash +Icon=trashcan_empty +Type=Application +#X-DocPath=kcontrol/kcmcgi/index.html + +X-TDE-ModuleType=Library +X-TDE-Library=trash +Categories=Qt;TDE;X-TDE-settings-system; + +Name=Trash +Name[cz]=Koš +Name[fr]=Corbeille +Name[it]=Cestino + +Comment=Trash Properties +Comment[cz]=Vlastnosti koše +Comment[fr]=Propriétés de la Corbeille +Comment[it]=Proprietà del cestino + +Keywords=trash;properties;size;limits;delete +Keywords[cz]=koš,vlastnosti,velikost,limity,odstranit +Keywords[fr]=corbeille;propriétés;taille;limites;supprimer +Keywords[it]=cestino;proprietà;dimensioni;limiti;cancella diff --git a/tdeioslave/trash/kcm_trash.h b/tdeioslave/trash/kcm_trash.h new file mode 100644 index 000000000..4987ccfba --- /dev/null +++ b/tdeioslave/trash/kcm_trash.h @@ -0,0 +1,47 @@ +/* + This file is part of the TDE Project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KCM_TRASH_H +#define KCM_TRASH_H + +#include <tdecmodule.h> + +class KTrashPropsPanel; +class KTrashPropsWidget; +class TQTabWidget; + +class TrashModule : public TDECModule +{ + Q_OBJECT + +public: + TrashModule(TQWidget *parent, const char *name); + + virtual void load(); + virtual void save(); + virtual void defaults(); + virtual TQString quickHelp() const; + +private: + TQTabWidget *tab; + KTrashPropsWidget *policyWidget; + +protected slots: +}; + +#endif diff --git a/tdeioslave/trash/ktrashpropsdlgplugin.cpp b/tdeioslave/trash/ktrashpropsdlgplugin.cpp index 1677c282a..5147481bc 100644 --- a/tdeioslave/trash/ktrashpropsdlgplugin.cpp +++ b/tdeioslave/trash/ktrashpropsdlgplugin.cpp @@ -21,6 +21,7 @@ */ #include "ktrashpropsdlgplugin.h" +#include "ktrashpropswidget.h" #include "discspaceutil.h" #include "trash_constant.h" #include "trashimpl.h" @@ -74,7 +75,9 @@ KTrashPropsDlgPlugin::KTrashPropsDlgPlugin( KPropertiesDialog *dialog, const cha readConfig(); - TQFrame *frame = dialog->addPage( i18n( "Size Limits" ) ); + TQFrame *frame = dialog->addPage(i18n("Polic&y")); + policyWidget = NULL; + setupGui( frame ); mUseTimeLimit->setChecked( mConfigMap[ mCurrentTrash ].useTimeLimit ); diff --git a/tdeioslave/trash/ktrashpropsdlgplugin.desktop b/tdeioslave/trash/ktrashpropsdlgplugin.desktop index 76ed40daf..b12061bc4 100644 --- a/tdeioslave/trash/ktrashpropsdlgplugin.desktop +++ b/tdeioslave/trash/ktrashpropsdlgplugin.desktop @@ -1,8 +1,10 @@ [Desktop Entry] Type=Service + +X-TDE-Library=ktrashpropsdlgplugin +X-TDE-ServiceTypes=KPropsDlg/Plugin,media/builtin-trash,inode/directory + Name=Trash Properties -Name[bg]=Свойства на кошчето Name[cz]=Vlastnosti koše +Name[fr]=Propriétés de la Corbeille Name[it]=Proprietà del cestino -X-TDE-Library=ktrashpropsdlgplugin -X-TDE-ServiceTypes=KPropsDlg/Plugin,media/builtin-trash,inode/directory diff --git a/tdeioslave/trash/ktrashpropsdlgplugin.h b/tdeioslave/trash/ktrashpropsdlgplugin.h index d21dd4578..9eab58eb1 100644 --- a/tdeioslave/trash/ktrashpropsdlgplugin.h +++ b/tdeioslave/trash/ktrashpropsdlgplugin.h @@ -32,6 +32,7 @@ class TQLabel; class TQRadioButton; class TQSpinBox; class TrashImpl; +class KTrashPropsWidget; class KTrashPropsDlgPlugin : public KPropsDlgPlugin { @@ -51,8 +52,10 @@ class KTrashPropsDlgPlugin : public KPropsDlgPlugin void rbFixedSizeToggled( bool ); void trashChanged( int ); void useTypeChanged(); - + private: + KTrashPropsWidget *policyWidget; + void readConfig(); void writeConfig(); void setupGui( TQFrame *frame ); diff --git a/tdeioslave/trash/ktrashpropswidget.cpp b/tdeioslave/trash/ktrashpropswidget.cpp new file mode 100644 index 000000000..b4f5c5e6f --- /dev/null +++ b/tdeioslave/trash/ktrashpropswidget.cpp @@ -0,0 +1,465 @@ +/* + This file is part of the TDE project + + Copyright (C) 2008 Tobias Koenig <[email protected]> + Copyright (C) 2016 Emanoil Kotsev <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "ktrashpropswidget.h" +#include "discspaceutil.h" +#include "trash_constant.h" +#include "trashimpl.h" + +#include <kdialog.h> +#include <knuminput.h> +#include <tqbuttongroup.h> +#include <tqcheckbox.h> +#include <tqcombobox.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqlistbox.h> +#include <tqradiobutton.h> +#include <tqspinbox.h> +#include <tqwidget.h> + +#include <kiconloader.h> +#include <tdelocale.h> + +using namespace TrashConstant; + + +KTrashPropsWidget::KTrashPropsWidget(TQWidget *parent, const char *name) + : TQWidget(parent, name) +{ + mTrashImpl = new TrashImpl(); + mTrashImpl->init(); + + setupGui(); + connect(mUseTimeLimit, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(useTypeChanged())); + connect(mDays, TQT_SIGNAL(valueChanged(int)),this, TQT_SLOT(setDirty())); + connect(mUseSizeLimit, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(useTypeChanged())); + connect(mPercentSize, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(percentSizeChanged(double))); + connect(mFixedSize, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(fixedSizeChanged(double))); + connect(mFixedSizeUnit, TQT_SIGNAL(activated(int)), this, TQT_SLOT(fixedSizeUnitActivated(int))); + connect(mRbPercentSize, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(rbPercentSizeToggled(bool))); + connect(mRbFixedSize, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(rbFixedSizeToggled(bool))); + connect(mLimitReachedAction, TQT_SIGNAL(activated(int)), this, TQT_SLOT(setDirty())); + + inhibitChangedSignal = true; + load(); + trashChanged(0); +} + +KTrashPropsWidget::~KTrashPropsWidget() +{ +} + +void KTrashPropsWidget::setupGui() +{ + TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories(); + int multiTrashRow = (map.count() > 1) ? 1 : 0; + TQGridLayout *wlayout = new TQGridLayout(this, multiTrashRow + 6, 5, 11, KDialog::spacingHint()); + if (multiTrashRow) + { + // If we have multiple trashes, we setup a widget to choose which trash to configure + TQListBox *mountPoints = new TQListBox(this); + wlayout->addMultiCellWidget(mountPoints, 0, 0, 0, 3); + + const TQPixmap folderPixmap = TDEGlobal::iconLoader()->loadIcon("folder", TDEIcon::Small); + TQMapConstIterator<int, TQString> it; + for (it = map.begin(); it != map.end(); ++it) + { + DiscSpaceUtil util(it.data()); + mountPoints->insertItem(folderPixmap, util.mountPoint(), it.key()); + } + mountPoints->setCurrentItem(0); + connect(mountPoints, TQT_SIGNAL(highlighted(int)), TQT_SLOT(trashChanged(int))); + } + else + { + mCurrentTrash = map[0]; + } + + mUseTimeLimit = new TQCheckBox(i18n("Delete files older than:"), this); + wlayout->addMultiCellWidget(mUseTimeLimit, multiTrashRow + 0, multiTrashRow + 0, 0, 1); + mDays = new TQSpinBox(1, 365, 1, this); + mDays->setSuffix(" days"); + wlayout->addMultiCellWidget(mDays, multiTrashRow + 0, multiTrashRow + 0, 2, 3); + + mUseSizeLimit = new TQCheckBox(i18n("Limit to maximum size"), this); + wlayout->addMultiCellWidget(mUseSizeLimit, multiTrashRow + 1, multiTrashRow + 1, 0, 1); + + mRbPercentSize = new TQRadioButton(i18n("&Percentage:"), this); + mRbFixedSize = new TQRadioButton(i18n("&Fixed size:"), this); + wlayout->addWidget(mRbPercentSize, multiTrashRow + 2, 1); + wlayout->addWidget(mRbFixedSize, multiTrashRow + 3, 1); + + mPercentSize = new KDoubleSpinBox(0, 100, 0.1, 10, 2, this); + mPercentSize->setSuffix(" %"); + wlayout->addWidget(mPercentSize, multiTrashRow + 2, 2); + mSizeLabel = new TQLabel(this); + wlayout->addWidget(mSizeLabel, multiTrashRow + 2, 3); + + mFixedSize = new KDoubleSpinBox(0, 1024*1024, 1, 500, 2, this); + wlayout->addWidget(mFixedSize, multiTrashRow + 3, 2); + mFixedSizeUnit = new TQComboBox(this); + mFixedSizeUnit->setEditable(false); + mFixedSizeUnit->insertItem(i18n("Bytes"), SIZE_ID_B); + mFixedSizeUnit->insertItem(i18n("KBytes"), SIZE_ID_KB); + mFixedSizeUnit->insertItem(i18n("MBytes"), SIZE_ID_MB); + mFixedSizeUnit->insertItem(i18n("GBytes"), SIZE_ID_GB); + mFixedSizeUnit->insertItem(i18n("TBytes"), SIZE_ID_TB); + mFixedSizeUnit->setCurrentItem(2); + wlayout->addWidget(mFixedSizeUnit, multiTrashRow + 3, 3); + + mLimitLabel = new TQLabel(i18n("When limit reached:"), this); + wlayout->addWidget(mLimitLabel, multiTrashRow + 4, 1); + + mLimitReachedAction = new TQComboBox(this); + mLimitReachedAction->insertItem(i18n("Warn me")); + mLimitReachedAction->insertItem(i18n("Delete oldest files from trash")); + mLimitReachedAction->insertItem(i18n("Delete biggest files from trash")); + wlayout->addMultiCellWidget(mLimitReachedAction, multiTrashRow + 4, multiTrashRow + 4, 2, 3); + + wlayout->setRowStretch(multiTrashRow + 6, 10); // Empty space at the bottom + wlayout->setColStretch(4, 10); // Empty space at the right hand side +} + +void KTrashPropsWidget::setDirty() +{ + if (!inhibitChangedSignal) + { + emit changed(true); + } +} + +void KTrashPropsWidget::load() +{ + readConfig(); + + mUseTimeLimit->setChecked(mConfigMap[mCurrentTrash].useTimeLimit); + mUseSizeLimit->setChecked(mConfigMap[mCurrentTrash].useSizeLimit); + mSizeLimitType = mConfigMap[mCurrentTrash].sizeLimitType; + if (mSizeLimitType == SIZE_LIMIT_FIXED) + { + mRbFixedSize->setChecked(true); + } + else + { + mRbPercentSize->setChecked(true); + } + mDays->setValue(mConfigMap[mCurrentTrash].days); + mPercentSize->setValue(mConfigMap[mCurrentTrash].percent); + mFixedSize->setValue(mConfigMap[mCurrentTrash].fixedSize); + mFixedSizeUnit->setCurrentItem(mConfigMap[mCurrentTrash].fixedSizeUnit); + mLimitReachedAction->setCurrentItem(mConfigMap[mCurrentTrash].actionType); + percentSizeChanged(mPercentSize->value()); + fixedSizeChanged(mFixedSize->value()); + useTypeChanged(); + + inhibitChangedSignal = false; +} + +void KTrashPropsWidget::save() +{ + if (!mCurrentTrash.isEmpty()) + { + ConfigEntry entry; + entry.useTimeLimit = mUseTimeLimit->isChecked(); + entry.days = mDays->value(); + entry.useSizeLimit = mUseSizeLimit->isChecked(); + if (mRbFixedSize->isChecked()) + { + entry.sizeLimitType = SIZE_LIMIT_FIXED; + } + else + { + entry.sizeLimitType = SIZE_LIMIT_PERCENT; + } + entry.percent = mPercentSize->value(); + entry.fixedSize = mFixedSize->value(); + entry.fixedSizeUnit = mFixedSizeUnit->currentItem(); + entry.actionType = mLimitReachedAction->currentItem(); + mConfigMap.insert(mCurrentTrash, entry); + } + + writeConfig(); +} + +void KTrashPropsWidget::setDefaultValues() +{ + mUseTimeLimit->setChecked(false); + mUseSizeLimit->setChecked(false); + mSizeLimitType = SIZE_LIMIT_PERCENT; + if (mSizeLimitType == SIZE_LIMIT_FIXED) + { + mRbFixedSize->setChecked(true); + } + else + { + mRbPercentSize->setChecked(true); + } + + mDays->setValue(mConfigMap[mCurrentTrash].days); + mPercentSize->setValue(1); + mFixedSize->setValue(500); + mFixedSizeUnit->setCurrentItem(SIZE_ID_MB); + mLimitReachedAction->setCurrentItem(0); + percentSizeChanged(mPercentSize->value()); + fixedSizeChanged(mFixedSize->value()); + + useTypeChanged(); +} + +void KTrashPropsWidget::percentSizeChanged(double percent) +{ + DiscSpaceUtil util(mCurrentTrash); + double partitionSize = util.size() * 1024.0; // convert to byte + double size = partitionSize*(percent/100.0); + + TQString unit = i18n("Bytes"); + if (size >= 1024) { + unit = i18n("KBytes"); + size = size/1024.0; + } + if (size >= 1024) { + unit = i18n("MBytes"); + size = size/1024.0; + } + if (size >= 1024) { + unit = i18n("GBytes"); + size = size/1024.0; + } + if (size >= 1024) { + unit = i18n("TBytes"); + size = size/1024.0; + } + + mSizeLabel->setText(i18n("(%1 %2)").arg(TQString::number(size, 'f', 2)).arg(unit)); + + setDirty(); +} + +void KTrashPropsWidget::fixedSizeChanged(double value) +{ + int currItem = mFixedSizeUnit->currentItem(); + if (value > 1023.999 && currItem >= SIZE_ID_TB) + { + // Max limit 1024 TBytes + mFixedSizeUnit->setCurrentItem(SIZE_ID_TB); + mFixedSize->setValue(1024.0); + } + else if (value > 1023.999 && currItem < SIZE_ID_TB) + { + // Scale up to higher measure unit + while (value > 1023.999 && currItem < SIZE_ID_TB) + { + ++currItem; + value /= 1024.0; + } + mFixedSizeUnit->setCurrentItem(currItem); + mFixedSize->setValue(value); + } + else if (value < 0.001) + { + // Scale down to lower measure unit + int currItem = mFixedSizeUnit->currentItem(); + if (currItem > SIZE_ID_B) + { + mFixedSizeUnit->setCurrentItem(currItem - 1); + mFixedSize->setValue(1023.0); + } + } + // Need to call this manually because "activated" is not emitted by "mFixedSizeUnit" + // when the index is changed programmatically (see TQComboBox API docs) + fixedSizeUnitActivated(mFixedSizeUnit->currentItem()); + + setDirty(); +} + +void KTrashPropsWidget::fixedSizeUnitActivated(int index) +{ + // Bytes can not be split into fractions + if (index == SIZE_ID_B) + { + mFixedSize->setPrecision(0); + } + else + { + mFixedSize->setPrecision(2); + } + + setDirty(); +} + +void KTrashPropsWidget::rbPercentSizeToggled(bool buttonOn) +{ + if (buttonOn) + { + mRbFixedSize->setChecked(false); + mSizeLimitType = SIZE_LIMIT_PERCENT; + } + else if (!mRbFixedSize->isChecked()) + { + // Set the button back on if the user clicked it twice + mRbPercentSize->setChecked(true); + } + + setDirty(); +} + +void KTrashPropsWidget::rbFixedSizeToggled(bool buttonOn) +{ + if (buttonOn) + { + mRbPercentSize->setChecked(false); + mSizeLimitType = SIZE_LIMIT_FIXED; + } + else if (!mRbPercentSize->isChecked()) + { + // Set the button back on if the user clicked it twice + mRbFixedSize->setChecked(true); + } + + setDirty(); +} + +void KTrashPropsWidget::trashChanged(int value) +{ + inhibitChangedSignal = true; + + const TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories(); + if (!mCurrentTrash.isEmpty()) { + ConfigEntry entry; + entry.useTimeLimit = mUseTimeLimit->isChecked(); + entry.days = mDays->value(); + entry.useSizeLimit = mUseSizeLimit->isChecked(); + entry.sizeLimitType = mSizeLimitType; + entry.percent = mPercentSize->value(), + entry.fixedSize = mFixedSize->value(); + entry.fixedSizeUnit = mFixedSizeUnit->currentItem(); + entry.actionType = mLimitReachedAction->currentItem(); + mConfigMap.insert(mCurrentTrash, entry); + } + mCurrentTrash = map[value]; + if (mConfigMap.contains(mCurrentTrash)) + { + const ConfigEntry entry = mConfigMap[mCurrentTrash]; + mUseTimeLimit->setChecked(entry.useTimeLimit); + mDays->setValue(entry.days); + mUseSizeLimit->setChecked(entry.useSizeLimit); + if (mSizeLimitType == SIZE_LIMIT_FIXED) + { + mRbFixedSize->setChecked(true); + } + else + { + mRbPercentSize->setChecked(true); + } + mPercentSize->setValue(entry.percent); + mFixedSize->setValue(entry.fixedSize); + mFixedSizeUnit->setCurrentItem(entry.fixedSizeUnit); + mLimitReachedAction->setCurrentItem(entry.actionType); + } + else + { + mUseTimeLimit->setChecked(false); + mDays->setValue(7); + mUseSizeLimit->setChecked(true); + mRbPercentSize->setChecked(true); + mPercentSize->setValue(10.0); + mFixedSize->setValue(500); + mFixedSizeUnit->setCurrentItem(SIZE_ID_MB); + mLimitReachedAction->setCurrentItem(0); + } + percentSizeChanged(mPercentSize->value()); + fixedSizeChanged(mFixedSize->value()); + + inhibitChangedSignal = false; +} + +void KTrashPropsWidget::useTypeChanged() +{ + mDays->setEnabled(mUseTimeLimit->isChecked()); + mRbPercentSize->setEnabled(mUseSizeLimit->isChecked()); + mRbFixedSize->setEnabled(mUseSizeLimit->isChecked()); + mPercentSize->setEnabled(mUseSizeLimit->isChecked()); + mSizeLabel->setEnabled(mUseSizeLimit->isChecked()); + mFixedSize->setEnabled(mUseSizeLimit->isChecked()); + mFixedSizeUnit->setEnabled(mUseSizeLimit->isChecked()); + mLimitLabel->setEnabled(mUseSizeLimit->isChecked()); + mLimitReachedAction->setEnabled(mUseSizeLimit->isChecked()); + + setDirty(); +} + +void KTrashPropsWidget::readConfig() +{ + TDEConfig config("trashrc"); + mConfigMap.clear(); + + const TQStringList groups = config.groupList(); + for (uint i = 0; i < groups.count(); ++i) { + if (groups[i].startsWith("/")) { + config.setGroup(groups[i]); + ConfigEntry entry; + entry.useTimeLimit = config.readBoolEntry("UseTimeLimit", false); + entry.days = config.readNumEntry("Days", 7); + entry.useSizeLimit = config.readBoolEntry("UseSizeLimit", true); + entry.sizeLimitType = config.readNumEntry("SizeLimitType", SIZE_LIMIT_PERCENT); + entry.percent = config.readDoubleNumEntry("Percent", 10); + entry.fixedSize = config.readDoubleNumEntry("FixedSize", 500); + entry.fixedSizeUnit = config.readNumEntry("FixedSizeUnit", SIZE_ID_MB); + entry.actionType = config.readNumEntry("LimitReachedAction", 0); + mConfigMap.insert(groups[i], entry); + } + } +} + +void KTrashPropsWidget::writeConfig() +{ + TDEConfig config("trashrc"); + + // first delete all existing groups + const TQStringList groups = config.groupList(); + for (uint i = 0; i < groups.count(); ++i) + { + if (groups[i].startsWith("/")) + { + config.deleteGroup(groups[i]); + } + } + + TQMapConstIterator<TQString, ConfigEntry> it; + for (it = mConfigMap.begin(); it != mConfigMap.end(); ++it) + { + config.setGroup(it.key()); + config.writeEntry("UseTimeLimit", it.data().useTimeLimit); + config.writeEntry("Days", it.data().days); + config.writeEntry("UseSizeLimit", it.data().useSizeLimit); + config.writeEntry("SizeLimitType", it.data().sizeLimitType); + config.writeEntry("Percent", it.data().percent); + config.writeEntry("FixedSize", it.data().fixedSize); + config.writeEntry("FixedSizeUnit", it.data().fixedSizeUnit); + config.writeEntry("LimitReachedAction", it.data().actionType); + } + + config.sync(); +} + +#include "ktrashpropswidget.moc" diff --git a/tdeioslave/trash/ktrashpropswidget.h b/tdeioslave/trash/ktrashpropswidget.h new file mode 100644 index 000000000..8cebfcae4 --- /dev/null +++ b/tdeioslave/trash/ktrashpropswidget.h @@ -0,0 +1,93 @@ +/* + This file is part of the TDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KTRASHPROPSWIDGET_H +#define KTRASHPROPSWIDGET_H + +#include "kpropertiesdialog.h" + +class KDoubleSpinBox; +class TQCheckBox; +class TQComboBox; +class TQLabel; +class TQRadioButton; +class TQSpinBox; +class TrashImpl; + +class KTrashPropsWidget : public TQWidget +{ + Q_OBJECT + + public: + KTrashPropsWidget(TQWidget *parent=0, const char *name=0); + ~KTrashPropsWidget(); + + void load(); + void save(); + void setDefaultValues(); + + signals: + void changed(bool state); + + protected slots: + void setDirty(); + void percentSizeChanged(double); + void fixedSizeChanged(double); + void fixedSizeUnitActivated (int); + void rbPercentSizeToggled(bool); + void rbFixedSizeToggled(bool); + void trashChanged(int); + void useTypeChanged(); + + private: + void readConfig(); + void writeConfig(); + void setupGui(); + + TQCheckBox *mUseTimeLimit; + TQSpinBox *mDays; + TQCheckBox *mUseSizeLimit; + int mSizeLimitType; + TQRadioButton *mRbPercentSize, *mRbFixedSize; + KDoubleSpinBox *mPercentSize; + KDoubleSpinBox *mFixedSize; + TQComboBox *mFixedSizeUnit; + TQLabel *mSizeLabel, *mLimitLabel; + TQComboBox *mLimitReachedAction; + + TrashImpl *mTrashImpl; + TQString mCurrentTrash; + bool inhibitChangedSignal; + + typedef struct { + bool useTimeLimit; + int days; + bool useSizeLimit; + int sizeLimitType; + double percent; + double fixedSize; + int fixedSizeUnit; + int actionType; + } ConfigEntry; + + typedef TQMap<TQString, ConfigEntry> ConfigMap; + ConfigMap mConfigMap; +}; + +#endif |