Browse Source

Added TDE Control module for trash policy configuration.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
master
Michele Calgaro 1 month ago
parent
commit
691c9204a1
Signed by: Michele Calgaro <michele.calgaro@yahoo.it> GPG Key ID: 2A75B7CA8ADED5CF

+ 2
- 0
konqueror/sidebar/trees/init/trash.desktop View File

@@ -8,8 +8,10 @@ X-TDE-KonqSidebarModule=konqsidebar_tree
8 8
 
9 9
 Name=Trash Folder
10 10
 Name[cz]=Složka koše
11
+Name[fr]=Dossier Corbeille
11 12
 Name[it]=Cartella Cestino
12 13
 
13 14
 Comment=This folder displays the contents of your Trash Bin
14 15
 Comment[cz]=Tato složka zobrazuje obsah vašeho koše
16
+Comment[fr]=Ce dossier montre le contenu de votre corbeille
15 17
 Comment[it]=Questa cartella visualizza il contenuto del tuo Cestino

+ 15
- 5
tdeioslave/trash/CMakeLists.txt View File

@@ -26,19 +26,18 @@ link_directories(
26 26
 ##### other data ################################
27 27
 
28 28
 install( FILES ktrashpropsdlgplugin.desktop trash.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
29
+install( FILES kcm_trash.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
29 30
 
30 31
 
31 32
 ##### trashcommon (static) ######################
32
-
33 33
 set( target trashcommon )
34 34
 
35 35
 tde_add_library( ${target} STATIC_PIC AUTOMOC
36
-  SOURCES trashimpl.cpp discspaceutil.cpp 
36
+  SOURCES trashimpl.cpp discspaceutil.cpp ktrashpropswidget.cpp
37 37
 )
38 38
 
39 39
 
40 40
 ##### tdeio_trash (module) ########################
41
-
42 41
 set( target tdeio_trash )
43 42
 
44 43
 tde_add_kpart( ${target} AUTOMOC
@@ -47,8 +46,18 @@ tde_add_kpart( ${target} AUTOMOC
47 46
   DESTINATION ${PLUGIN_INSTALL_DIR}
48 47
 )
49 48
 
50
-##### ktrashpropsdlgplugin (module) ########################
51 49
 
50
+##### kcm_trash (module) ########################
51
+set( target kcm_trash )
52
+
53
+tde_add_kpart( ${target} AUTOMOC
54
+  SOURCES kcm_trash.cpp
55
+  LINK trashcommon-static tdeio-shared
56
+  DESTINATION ${PLUGIN_INSTALL_DIR}
57
+)
58
+
59
+
60
+##### ktrashpropsdlgplugin (module) ########################
52 61
 set( target ktrashpropsdlgplugin )
53 62
 
54 63
 tde_add_kpart( ${target} AUTOMOC
@@ -57,8 +66,8 @@ tde_add_kpart( ${target} AUTOMOC
57 66
   DESTINATION ${PLUGIN_INSTALL_DIR}
58 67
 )
59 68
 
60
-##### ktrash (executable) #######################
61 69
 
70
+##### ktrash (executable) #######################
62 71
 set( target ktrash )
63 72
 
64 73
 tde_add_executable( ${target}
@@ -67,6 +76,7 @@ tde_add_executable( ${target}
67 76
   DESTINATION ${BIN_INSTALL_DIR}
68 77
 )
69 78
 
79
+
70 80
 ##### testtrash (executable) #######################
71 81
 tde_add_executable( testtrash
72 82
   SOURCES testtrash.cpp AUTOMOC

+ 8
- 2
tdeioslave/trash/Makefile.am View File

@@ -3,12 +3,16 @@ METASOURCES = AUTO
3 3
 
4 4
 SUBDIRS = . tdefile-plugin
5 5
 
6
-kde_module_LTLIBRARIES = tdeio_trash.la ktrashpropsdlgplugin.la
6
+kde_module_LTLIBRARIES = tdeio_trash.la kcm_trash ktrashpropsdlgplugin.la
7 7
 
8 8
 tdeio_trash_la_SOURCES = tdeio_trash.cpp
9 9
 tdeio_trash_la_LIBADD  = libtrashcommon.la $(LIB_TDEIO)
10 10
 tdeio_trash_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined
11 11
 
12
+kcm_trash_la_SOURCES = kcm_trash.cpp
13
+kcm_trash_la_LIBADD  = libtrashcommon.la $(LIB_TDEIO)
14
+kcm_trash_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined
15
+
12 16
 bin_PROGRAMS = ktrash
13 17
 ktrash_SOURCES = ktrash.cpp
14 18
 ktrash_LDADD = $(LIB_TDEIO)
@@ -17,7 +21,7 @@ ktrash_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE)
17 21
 kde_services_DATA = trash.protocol
18 22
 
19 23
 noinst_LTLIBRARIES = libtrashcommon.la
20
-libtrashcommon_la_SOURCES = trashimpl.cpp discspaceutil.cpp
24
+libtrashcommon_la_SOURCES = trashimpl.cpp discspaceutil.cpp ktrashpropswidget.cpp
21 25
 
22 26
 check_PROGRAMS = testtrash
23 27
 testtrash_SOURCES = testtrash.cpp
@@ -38,3 +42,5 @@ ktrashpropsdlgplugin_la_LIBADD = $(LIB_TDEIO)
38 42
 
39 43
 services_DATA = ktrashpropsdlgplugin.desktop
40 44
 servicesdir = $(kde_servicesdir)
45
+
46
+xdg_apps_DATA = kcm_trash.desktop

+ 81
- 0
tdeioslave/trash/kcm_trash.cpp View File

@@ -0,0 +1,81 @@
1
+/*
2
+   This file is part of the TDE Project
3
+
4
+   This library is free software; you can redistribute it and/or
5
+   modify it under the terms of the GNU Library General Public
6
+   License version 2 as published by the Free Software Foundation.
7
+
8
+   This library is distributed in the hope that it will be useful,
9
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+   Library General Public License for more details.
12
+
13
+   You should have received a copy of the GNU Library General Public License
14
+   along with this library; see the file COPYING.LIB.  If not, write to
15
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
+   Boston, MA 02110-1301, USA.
17
+*/
18
+
19
+#include "kcm_trash.h"
20
+#include "ktrashpropswidget.h"
21
+
22
+#include <tqlayout.h>
23
+#include <tqtabwidget.h>
24
+#include <tdelocale.h>
25
+#include <tdeglobal.h>
26
+#include <tdeaboutdata.h>
27
+#include <kdialog.h>
28
+
29
+
30
+extern "C"
31
+{
32
+  KDE_EXPORT TDECModule *create_trash(TQWidget *parent, const char *)
33
+  {
34
+    return new TrashModule(parent, "trash");
35
+  }
36
+}
37
+
38
+
39
+TrashModule::TrashModule(TQWidget *parent, const char *name)
40
+	: TDECModule(parent, name)
41
+{
42
+	TDEAboutData * about = new TDEAboutData("trash",
43
+	                                    I18N_NOOP("Trash"), "1",
44
+	                                    I18N_NOOP("Trash Control Panel Module"),
45
+	                                    TDEAboutData::License_GPL_V2,
46
+	                                    I18N_NOOP("(c) 2019 Michele Calgaro"));
47
+	setAboutData( about );
48
+  TDEGlobal::locale()->insertCatalogue("trash");
49
+
50
+  tab = new TQTabWidget(this);
51
+
52
+	policyWidget = new KTrashPropsWidget(this);
53
+  tab->addTab(policyWidget, i18n("Trash Polic&y"));
54
+  connect(policyWidget, TQT_SIGNAL(changed(bool)), TQT_SIGNAL(changed(bool)));
55
+
56
+  TQVBoxLayout *top = new TQVBoxLayout(this);
57
+  top->addWidget(tab);
58
+}
59
+
60
+void TrashModule::load()
61
+{
62
+  policyWidget->load();
63
+}
64
+
65
+void TrashModule::save()
66
+{
67
+  policyWidget->save();
68
+}
69
+
70
+void TrashModule::defaults()
71
+{
72
+  policyWidget->setDefaultValues();
73
+}
74
+
75
+TQString TrashModule::quickHelp() const
76
+{
77
+  return i18n("<h1>Trash</h1> Here you can choose the settings "
78
+              "for your Trash Bin size and clean up policy. ");
79
+}
80
+
81
+#include "kcm_trash.moc"

+ 24
- 0
tdeioslave/trash/kcm_trash.desktop View File

@@ -0,0 +1,24 @@
1
+[Desktop Entry]
2
+Exec=tdecmshell kcm_trash
3
+Icon=trashcan_empty
4
+Type=Application
5
+#X-DocPath=kcontrol/kcmcgi/index.html
6
+
7
+X-TDE-ModuleType=Library
8
+X-TDE-Library=trash
9
+Categories=Qt;TDE;X-TDE-settings-system;
10
+
11
+Name=Trash
12
+Name[cz]=Koš
13
+Name[fr]=Corbeille
14
+Name[it]=Cestino
15
+
16
+Comment=Trash Properties
17
+Comment[cz]=Vlastnosti koše
18
+Comment[fr]=Propriétés de la Corbeille
19
+Comment[it]=Proprietà del cestino
20
+
21
+Keywords=trash;properties;size;limits;delete
22
+Keywords[cz]=koš,vlastnosti,velikost,limity,odstranit
23
+Keywords[fr]=corbeille;propriétés;taille;limites;supprimer
24
+Keywords[it]=cestino;proprietà;dimensioni;limiti;cancella

+ 47
- 0
tdeioslave/trash/kcm_trash.h View File

@@ -0,0 +1,47 @@
1
+/*
2
+   This file is part of the TDE Project
3
+
4
+   This library is free software; you can redistribute it and/or
5
+   modify it under the terms of the GNU Library General Public
6
+   License version 2 as published by the Free Software Foundation.
7
+
8
+   This library is distributed in the hope that it will be useful,
9
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+   Library General Public License for more details.
12
+
13
+   You should have received a copy of the GNU Library General Public License
14
+   along with this library; see the file COPYING.LIB.  If not, write to
15
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
+   Boston, MA 02110-1301, USA.
17
+*/
18
+
19
+#ifndef KCM_TRASH_H
20
+#define KCM_TRASH_H
21
+
22
+#include <tdecmodule.h>
23
+
24
+class KTrashPropsPanel;
25
+class KTrashPropsWidget;
26
+class TQTabWidget;
27
+
28
+class TrashModule : public TDECModule
29
+{
30
+	Q_OBJECT
31
+
32
+public:
33
+	TrashModule(TQWidget *parent, const char *name);
34
+
35
+	virtual void load();
36
+	virtual void save();
37
+	virtual void defaults();
38
+	virtual TQString quickHelp() const;
39
+
40
+private:
41
+  TQTabWidget	*tab;
42
+	KTrashPropsWidget *policyWidget;
43
+
44
+protected slots:
45
+};
46
+
47
+#endif

+ 4
- 1
tdeioslave/trash/ktrashpropsdlgplugin.cpp View File

@@ -21,6 +21,7 @@
21 21
 */
22 22
 
23 23
 #include "ktrashpropsdlgplugin.h"
24
+#include "ktrashpropswidget.h"
24 25
 #include "discspaceutil.h"
25 26
 #include "trash_constant.h"
26 27
 #include "trashimpl.h"
@@ -74,7 +75,9 @@ KTrashPropsDlgPlugin::KTrashPropsDlgPlugin( KPropertiesDialog *dialog, const cha
74 75
 
75 76
   readConfig();
76 77
 
77
-  TQFrame *frame = dialog->addPage( i18n( "Size Limits" ) );
78
+  TQFrame *frame = dialog->addPage(i18n("Polic&y"));
79
+	policyWidget = NULL;
80
+
78 81
   setupGui( frame );
79 82
 
80 83
   mUseTimeLimit->setChecked( mConfigMap[ mCurrentTrash ].useTimeLimit );

+ 5
- 3
tdeioslave/trash/ktrashpropsdlgplugin.desktop View File

@@ -1,8 +1,10 @@
1 1
 [Desktop Entry]
2 2
 Type=Service
3
+
4
+X-TDE-Library=ktrashpropsdlgplugin
5
+X-TDE-ServiceTypes=KPropsDlg/Plugin,media/builtin-trash,inode/directory
6
+
3 7
 Name=Trash Properties
4
-Name[bg]=Свойства на кошчето
5 8
 Name[cz]=Vlastnosti koše
9
+Name[fr]=Propriétés de la Corbeille
6 10
 Name[it]=Proprietà del cestino
7
-X-TDE-Library=ktrashpropsdlgplugin
8
-X-TDE-ServiceTypes=KPropsDlg/Plugin,media/builtin-trash,inode/directory

+ 4
- 1
tdeioslave/trash/ktrashpropsdlgplugin.h View File

@@ -32,6 +32,7 @@ class TQLabel;
32 32
 class TQRadioButton;
33 33
 class TQSpinBox;
34 34
 class TrashImpl;
35
+class KTrashPropsWidget;
35 36
 
36 37
 class KTrashPropsDlgPlugin : public KPropsDlgPlugin
37 38
 {
@@ -51,8 +52,10 @@ class KTrashPropsDlgPlugin : public KPropsDlgPlugin
51 52
 		void rbFixedSizeToggled( bool );
52 53
     void trashChanged( int );
53 54
     void useTypeChanged();
54
-  	
55
+
55 56
   private:
57
+		KTrashPropsWidget *policyWidget;
58
+
56 59
     void readConfig();
57 60
     void writeConfig();
58 61
     void setupGui( TQFrame *frame );

+ 465
- 0
tdeioslave/trash/ktrashpropswidget.cpp View File

@@ -0,0 +1,465 @@
1
+/*
2
+   This file is part of the TDE project
3
+
4
+   Copyright (C) 2008 Tobias Koenig <tokoe@kde.org>
5
+   Copyright (C) 2016 Emanoil Kotsev <deloptes@yahoo.com>
6
+
7
+   This library is free software; you can redistribute it and/or
8
+   modify it under the terms of the GNU Library General Public
9
+   License as published by the Free Software Foundation; either
10
+   version 2 of the License, or (at your option) any later version.
11
+
12
+   This library is distributed in the hope that it will be useful,
13
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+   Library General Public License for more details.
16
+
17
+   You should have received a copy of the GNU Library General Public License
18
+   along with this library; see the file COPYING.LIB.  If not, write to
19
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
+   Boston, MA 02110-1301, USA.
21
+*/
22
+
23
+#include "ktrashpropswidget.h"
24
+#include "discspaceutil.h"
25
+#include "trash_constant.h"
26
+#include "trashimpl.h"
27
+
28
+#include <kdialog.h>
29
+#include <knuminput.h>
30
+#include <tqbuttongroup.h>
31
+#include <tqcheckbox.h>
32
+#include <tqcombobox.h>
33
+#include <tqlabel.h>
34
+#include <tqlayout.h>
35
+#include <tqlistbox.h>
36
+#include <tqradiobutton.h>
37
+#include <tqspinbox.h>
38
+#include <tqwidget.h>
39
+
40
+#include <kiconloader.h>
41
+#include <tdelocale.h>
42
+
43
+using namespace TrashConstant;
44
+
45
+
46
+KTrashPropsWidget::KTrashPropsWidget(TQWidget *parent, const char *name)
47
+		: TQWidget(parent, name)
48
+{
49
+  mTrashImpl = new TrashImpl();
50
+  mTrashImpl->init();
51
+
52
+  setupGui();
53
+  connect(mUseTimeLimit, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(useTypeChanged()));
54
+  connect(mDays, TQT_SIGNAL(valueChanged(int)),this, TQT_SLOT(setDirty()));
55
+  connect(mUseSizeLimit, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(useTypeChanged()));
56
+  connect(mPercentSize, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(percentSizeChanged(double)));
57
+  connect(mFixedSize, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(fixedSizeChanged(double)));
58
+  connect(mFixedSizeUnit, TQT_SIGNAL(activated(int)), this, TQT_SLOT(fixedSizeUnitActivated(int)));
59
+  connect(mRbPercentSize, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(rbPercentSizeToggled(bool)));
60
+  connect(mRbFixedSize, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(rbFixedSizeToggled(bool)));
61
+  connect(mLimitReachedAction, TQT_SIGNAL(activated(int)), this, TQT_SLOT(setDirty()));
62
+
63
+  inhibitChangedSignal = true;
64
+  load();
65
+  trashChanged(0);
66
+}
67
+
68
+KTrashPropsWidget::~KTrashPropsWidget()
69
+{
70
+}
71
+
72
+void KTrashPropsWidget::setupGui()
73
+{
74
+  TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
75
+  int multiTrashRow = (map.count() > 1) ? 1 : 0;
76
+  TQGridLayout *wlayout = new TQGridLayout(this, multiTrashRow + 6, 5, 11, KDialog::spacingHint());
77
+  if (multiTrashRow)
78
+  {
79
+    // If we have multiple trashes, we setup a widget to choose which trash to configure
80
+    TQListBox *mountPoints = new TQListBox(this);
81
+	  wlayout->addMultiCellWidget(mountPoints, 0, 0, 0, 3);
82
+
83
+    const TQPixmap folderPixmap = TDEGlobal::iconLoader()->loadIcon("folder", TDEIcon::Small);
84
+    TQMapConstIterator<int, TQString> it;
85
+    for (it = map.begin(); it != map.end(); ++it)
86
+    {
87
+      DiscSpaceUtil util(it.data());
88
+      mountPoints->insertItem(folderPixmap, util.mountPoint(), it.key());
89
+    }
90
+    mountPoints->setCurrentItem(0);
91
+    connect(mountPoints, TQT_SIGNAL(highlighted(int)), TQT_SLOT(trashChanged(int)));
92
+  }
93
+  else
94
+  {
95
+    mCurrentTrash = map[0];
96
+  }
97
+
98
+  mUseTimeLimit = new TQCheckBox(i18n("Delete files older than:"), this);
99
+  wlayout->addMultiCellWidget(mUseTimeLimit, multiTrashRow + 0, multiTrashRow + 0, 0, 1);
100
+  mDays = new TQSpinBox(1, 365, 1, this);
101
+  mDays->setSuffix(" days");
102
+  wlayout->addMultiCellWidget(mDays, multiTrashRow + 0, multiTrashRow + 0, 2, 3);
103
+
104
+  mUseSizeLimit = new TQCheckBox(i18n("Limit to maximum size"), this);
105
+  wlayout->addMultiCellWidget(mUseSizeLimit, multiTrashRow + 1, multiTrashRow + 1, 0, 1);
106
+
107
+  mRbPercentSize = new TQRadioButton(i18n("&Percentage:"), this);
108
+  mRbFixedSize = new TQRadioButton(i18n("&Fixed size:"), this);
109
+  wlayout->addWidget(mRbPercentSize, multiTrashRow + 2, 1);
110
+  wlayout->addWidget(mRbFixedSize, multiTrashRow + 3, 1);
111
+
112
+  mPercentSize = new KDoubleSpinBox(0, 100, 0.1, 10, 2, this);
113
+  mPercentSize->setSuffix(" %");
114
+  wlayout->addWidget(mPercentSize, multiTrashRow + 2, 2);
115
+  mSizeLabel = new TQLabel(this);
116
+  wlayout->addWidget(mSizeLabel, multiTrashRow + 2, 3);
117
+
118
+  mFixedSize = new KDoubleSpinBox(0, 1024*1024, 1, 500, 2, this);
119
+  wlayout->addWidget(mFixedSize, multiTrashRow + 3, 2);
120
+  mFixedSizeUnit = new TQComboBox(this);
121
+  mFixedSizeUnit->setEditable(false);
122
+  mFixedSizeUnit->insertItem(i18n("Bytes"), SIZE_ID_B);
123
+  mFixedSizeUnit->insertItem(i18n("KBytes"), SIZE_ID_KB);
124
+  mFixedSizeUnit->insertItem(i18n("MBytes"), SIZE_ID_MB);
125
+  mFixedSizeUnit->insertItem(i18n("GBytes"), SIZE_ID_GB);
126
+  mFixedSizeUnit->insertItem(i18n("TBytes"), SIZE_ID_TB);
127
+  mFixedSizeUnit->setCurrentItem(2);
128
+  wlayout->addWidget(mFixedSizeUnit, multiTrashRow + 3, 3);
129
+
130
+  mLimitLabel = new TQLabel(i18n("When limit reached:"), this);
131
+  wlayout->addWidget(mLimitLabel, multiTrashRow + 4, 1);
132
+
133
+  mLimitReachedAction = new TQComboBox(this);
134
+  mLimitReachedAction->insertItem(i18n("Warn me"));
135
+  mLimitReachedAction->insertItem(i18n("Delete oldest files from trash"));
136
+  mLimitReachedAction->insertItem(i18n("Delete biggest files from trash"));
137
+  wlayout->addMultiCellWidget(mLimitReachedAction, multiTrashRow + 4, multiTrashRow + 4, 2, 3);
138
+
139
+  wlayout->setRowStretch(multiTrashRow + 6, 10);  // Empty space at the bottom
140
+  wlayout->setColStretch(4, 10);  // Empty space at the right hand side
141
+}
142
+
143
+void KTrashPropsWidget::setDirty()
144
+{
145
+	if (!inhibitChangedSignal)
146
+	{
147
+		emit changed(true);
148
+	}
149
+}
150
+
151
+void KTrashPropsWidget::load()
152
+{
153
+  readConfig();
154
+
155
+  mUseTimeLimit->setChecked(mConfigMap[mCurrentTrash].useTimeLimit);
156
+  mUseSizeLimit->setChecked(mConfigMap[mCurrentTrash].useSizeLimit);
157
+  mSizeLimitType = mConfigMap[mCurrentTrash].sizeLimitType;
158
+	if (mSizeLimitType == SIZE_LIMIT_FIXED)
159
+	{
160
+		mRbFixedSize->setChecked(true);
161
+	}
162
+	else
163
+	{
164
+		mRbPercentSize->setChecked(true);
165
+	}
166
+  mDays->setValue(mConfigMap[mCurrentTrash].days);
167
+  mPercentSize->setValue(mConfigMap[mCurrentTrash].percent);
168
+  mFixedSize->setValue(mConfigMap[mCurrentTrash].fixedSize);
169
+  mFixedSizeUnit->setCurrentItem(mConfigMap[mCurrentTrash].fixedSizeUnit);
170
+  mLimitReachedAction->setCurrentItem(mConfigMap[mCurrentTrash].actionType);
171
+  percentSizeChanged(mPercentSize->value());
172
+  fixedSizeChanged(mFixedSize->value());
173
+  useTypeChanged();
174
+
175
+  inhibitChangedSignal = false;
176
+}
177
+
178
+void KTrashPropsWidget::save()
179
+{
180
+  if (!mCurrentTrash.isEmpty())
181
+  {
182
+    ConfigEntry entry;
183
+    entry.useTimeLimit = mUseTimeLimit->isChecked();
184
+    entry.days = mDays->value();
185
+    entry.useSizeLimit = mUseSizeLimit->isChecked();
186
+    if (mRbFixedSize->isChecked())
187
+    {
188
+      entry.sizeLimitType = SIZE_LIMIT_FIXED;
189
+    }
190
+    else
191
+    {
192
+      entry.sizeLimitType = SIZE_LIMIT_PERCENT;
193
+    }
194
+    entry.percent = mPercentSize->value();
195
+    entry.fixedSize = mFixedSize->value();
196
+    entry.fixedSizeUnit = mFixedSizeUnit->currentItem();
197
+    entry.actionType = mLimitReachedAction->currentItem();
198
+    mConfigMap.insert(mCurrentTrash, entry);
199
+  }
200
+
201
+  writeConfig();
202
+}
203
+
204
+void KTrashPropsWidget::setDefaultValues()
205
+{
206
+  mUseTimeLimit->setChecked(false);
207
+  mUseSizeLimit->setChecked(false);
208
+  mSizeLimitType = SIZE_LIMIT_PERCENT;
209
+	if (mSizeLimitType == SIZE_LIMIT_FIXED)
210
+	{
211
+		mRbFixedSize->setChecked(true);
212
+	}
213
+	else
214
+	{
215
+		mRbPercentSize->setChecked(true);
216
+	}
217
+
218
+  mDays->setValue(mConfigMap[mCurrentTrash].days);
219
+  mPercentSize->setValue(1);
220
+  mFixedSize->setValue(500);
221
+  mFixedSizeUnit->setCurrentItem(SIZE_ID_MB);
222
+  mLimitReachedAction->setCurrentItem(0);
223
+  percentSizeChanged(mPercentSize->value());
224
+  fixedSizeChanged(mFixedSize->value());
225
+
226
+  useTypeChanged();
227
+}
228
+
229
+void KTrashPropsWidget::percentSizeChanged(double percent)
230
+{
231
+  DiscSpaceUtil util(mCurrentTrash);
232
+  double partitionSize = util.size() * 1024.0; // convert to byte
233
+  double size = partitionSize*(percent/100.0);
234
+
235
+  TQString unit = i18n("Bytes");
236
+  if (size >= 1024) {
237
+    unit = i18n("KBytes");
238
+    size = size/1024.0;
239
+  }
240
+  if (size >= 1024) {
241
+    unit = i18n("MBytes");
242
+    size = size/1024.0;
243
+  }
244
+  if (size >= 1024) {
245
+    unit = i18n("GBytes");
246
+    size = size/1024.0;
247
+  }
248
+  if (size >= 1024) {
249
+    unit = i18n("TBytes");
250
+    size = size/1024.0;
251
+  }
252
+
253
+  mSizeLabel->setText(i18n("(%1 %2)").arg(TQString::number(size, 'f', 2)).arg(unit));
254
+
255
+  setDirty();
256
+}
257
+
258
+void KTrashPropsWidget::fixedSizeChanged(double value)
259
+{
260
+	int currItem = mFixedSizeUnit->currentItem();
261
+	if (value > 1023.999 && currItem >= SIZE_ID_TB)
262
+	{
263
+	  // Max limit 1024 TBytes
264
+		mFixedSizeUnit->setCurrentItem(SIZE_ID_TB);
265
+		mFixedSize->setValue(1024.0);
266
+	}
267
+	else if (value > 1023.999 && currItem < SIZE_ID_TB)
268
+	{
269
+		// Scale up to higher measure unit
270
+	  while (value > 1023.999 && currItem < SIZE_ID_TB)
271
+	  {
272
+		  ++currItem;
273
+		  value /= 1024.0;
274
+		}
275
+		mFixedSizeUnit->setCurrentItem(currItem);
276
+		mFixedSize->setValue(value);
277
+	}
278
+	else if (value < 0.001)
279
+	{
280
+		// Scale down to lower measure unit
281
+	  int currItem = mFixedSizeUnit->currentItem();
282
+	  if (currItem > SIZE_ID_B)
283
+	  {
284
+	    mFixedSizeUnit->setCurrentItem(currItem - 1);
285
+	    mFixedSize->setValue(1023.0);
286
+	  }
287
+	}
288
+	// Need to call this manually because "activated" is not emitted by "mFixedSizeUnit"
289
+	// when the index is changed programmatically (see TQComboBox API docs)
290
+	fixedSizeUnitActivated(mFixedSizeUnit->currentItem());
291
+
292
+  setDirty();
293
+}
294
+
295
+void KTrashPropsWidget::fixedSizeUnitActivated(int index)
296
+{
297
+	// Bytes can not be split into fractions
298
+	if (index == SIZE_ID_B)
299
+	{
300
+		mFixedSize->setPrecision(0);
301
+	}
302
+	else
303
+	{
304
+		mFixedSize->setPrecision(2);
305
+	}
306
+
307
+  setDirty();
308
+}
309
+
310
+void KTrashPropsWidget::rbPercentSizeToggled(bool buttonOn)
311
+{
312
+	if (buttonOn)
313
+	{
314
+		mRbFixedSize->setChecked(false);
315
+		mSizeLimitType = SIZE_LIMIT_PERCENT;
316
+	}
317
+	else if (!mRbFixedSize->isChecked())
318
+	{
319
+		// Set the button back on if the user clicked it twice
320
+		mRbPercentSize->setChecked(true);
321
+	}
322
+
323
+  setDirty();
324
+}
325
+
326
+void KTrashPropsWidget::rbFixedSizeToggled(bool buttonOn)
327
+{
328
+	if (buttonOn)
329
+	{
330
+		mRbPercentSize->setChecked(false);
331
+		mSizeLimitType = SIZE_LIMIT_FIXED;
332
+	}
333
+	else if (!mRbPercentSize->isChecked())
334
+	{
335
+		// Set the button back on if the user clicked it twice
336
+		mRbFixedSize->setChecked(true);
337
+	}
338
+
339
+  setDirty();
340
+}
341
+
342
+void KTrashPropsWidget::trashChanged(int value)
343
+{
344
+  inhibitChangedSignal = true;
345
+
346
+  const TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
347
+  if (!mCurrentTrash.isEmpty()) {
348
+    ConfigEntry entry;
349
+    entry.useTimeLimit = mUseTimeLimit->isChecked();
350
+    entry.days = mDays->value();
351
+    entry.useSizeLimit = mUseSizeLimit->isChecked();
352
+    entry.sizeLimitType = mSizeLimitType;
353
+    entry.percent = mPercentSize->value(),
354
+    entry.fixedSize = mFixedSize->value();
355
+    entry.fixedSizeUnit = mFixedSizeUnit->currentItem();
356
+    entry.actionType = mLimitReachedAction->currentItem();
357
+    mConfigMap.insert(mCurrentTrash, entry);
358
+  }
359
+  mCurrentTrash = map[value];
360
+  if (mConfigMap.contains(mCurrentTrash))
361
+  {
362
+    const ConfigEntry entry = mConfigMap[mCurrentTrash];
363
+    mUseTimeLimit->setChecked(entry.useTimeLimit);
364
+    mDays->setValue(entry.days);
365
+    mUseSizeLimit->setChecked(entry.useSizeLimit);
366
+		if (mSizeLimitType == SIZE_LIMIT_FIXED)
367
+		{
368
+			mRbFixedSize->setChecked(true);
369
+		}
370
+		else
371
+		{
372
+			mRbPercentSize->setChecked(true);
373
+		}
374
+    mPercentSize->setValue(entry.percent);
375
+		mFixedSize->setValue(entry.fixedSize);
376
+		mFixedSizeUnit->setCurrentItem(entry.fixedSizeUnit);
377
+    mLimitReachedAction->setCurrentItem(entry.actionType);
378
+  }
379
+  else
380
+  {
381
+    mUseTimeLimit->setChecked(false);
382
+    mDays->setValue(7);
383
+    mUseSizeLimit->setChecked(true);
384
+    mRbPercentSize->setChecked(true);
385
+    mPercentSize->setValue(10.0);
386
+		mFixedSize->setValue(500);
387
+		mFixedSizeUnit->setCurrentItem(SIZE_ID_MB);
388
+    mLimitReachedAction->setCurrentItem(0);
389
+  }
390
+  percentSizeChanged(mPercentSize->value());
391
+  fixedSizeChanged(mFixedSize->value());
392
+
393
+  inhibitChangedSignal = false;
394
+}
395
+
396
+void KTrashPropsWidget::useTypeChanged()
397
+{
398
+  mDays->setEnabled(mUseTimeLimit->isChecked());
399
+  mRbPercentSize->setEnabled(mUseSizeLimit->isChecked());
400
+  mRbFixedSize->setEnabled(mUseSizeLimit->isChecked());
401
+  mPercentSize->setEnabled(mUseSizeLimit->isChecked());
402
+  mSizeLabel->setEnabled(mUseSizeLimit->isChecked());
403
+  mFixedSize->setEnabled(mUseSizeLimit->isChecked());
404
+  mFixedSizeUnit->setEnabled(mUseSizeLimit->isChecked());
405
+  mLimitLabel->setEnabled(mUseSizeLimit->isChecked());
406
+  mLimitReachedAction->setEnabled(mUseSizeLimit->isChecked());
407
+
408
+  setDirty();
409
+}
410
+
411
+void KTrashPropsWidget::readConfig()
412
+{
413
+  TDEConfig config("trashrc");
414
+  mConfigMap.clear();
415
+
416
+  const TQStringList groups = config.groupList();
417
+  for (uint i = 0; i < groups.count(); ++i) {
418
+    if (groups[i].startsWith("/")) {
419
+      config.setGroup(groups[i]);
420
+      ConfigEntry entry;
421
+      entry.useTimeLimit = config.readBoolEntry("UseTimeLimit", false);
422
+      entry.days = config.readNumEntry("Days", 7);
423
+      entry.useSizeLimit = config.readBoolEntry("UseSizeLimit", true);
424
+	    entry.sizeLimitType = config.readNumEntry("SizeLimitType", SIZE_LIMIT_PERCENT);
425
+      entry.percent = config.readDoubleNumEntry("Percent", 10);
426
+      entry.fixedSize = config.readDoubleNumEntry("FixedSize", 500);
427
+      entry.fixedSizeUnit = config.readNumEntry("FixedSizeUnit", SIZE_ID_MB);
428
+      entry.actionType = config.readNumEntry("LimitReachedAction", 0);
429
+      mConfigMap.insert(groups[i], entry);
430
+    }
431
+  }
432
+}
433
+
434
+void KTrashPropsWidget::writeConfig()
435
+{
436
+  TDEConfig config("trashrc");
437
+
438
+  // first delete all existing groups
439
+  const TQStringList groups = config.groupList();
440
+  for (uint i = 0; i < groups.count(); ++i)
441
+  {
442
+    if (groups[i].startsWith("/"))
443
+    {
444
+      config.deleteGroup(groups[i]);
445
+    }
446
+  }
447
+
448
+  TQMapConstIterator<TQString, ConfigEntry> it;
449
+  for (it = mConfigMap.begin(); it != mConfigMap.end(); ++it)
450
+  {
451
+    config.setGroup(it.key());
452
+    config.writeEntry("UseTimeLimit", it.data().useTimeLimit);
453
+    config.writeEntry("Days", it.data().days);
454
+    config.writeEntry("UseSizeLimit", it.data().useSizeLimit);
455
+    config.writeEntry("SizeLimitType", it.data().sizeLimitType);
456
+    config.writeEntry("Percent", it.data().percent);
457
+    config.writeEntry("FixedSize", it.data().fixedSize);
458
+    config.writeEntry("FixedSizeUnit", it.data().fixedSizeUnit);
459
+    config.writeEntry("LimitReachedAction", it.data().actionType);
460
+  }
461
+
462
+  config.sync();
463
+}
464
+
465
+#include "ktrashpropswidget.moc"

+ 93
- 0
tdeioslave/trash/ktrashpropswidget.h View File

@@ -0,0 +1,93 @@
1
+/*
2
+   This file is part of the TDE project
3
+
4
+   This library is free software; you can redistribute it and/or
5
+   modify it under the terms of the GNU Library General Public
6
+   License as published by the Free Software Foundation; either
7
+   version 2 of the License, or (at your option) any later version.
8
+
9
+   This library is distributed in the hope that it will be useful,
10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+   Library General Public License for more details.
13
+
14
+   You should have received a copy of the GNU Library General Public License
15
+   along with this library; see the file COPYING.LIB.  If not, write to
16
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
+   Boston, MA 02110-1301, USA.
18
+*/
19
+
20
+#ifndef KTRASHPROPSWIDGET_H
21
+#define KTRASHPROPSWIDGET_H
22
+
23
+#include "kpropertiesdialog.h"
24
+
25
+class KDoubleSpinBox;
26
+class TQCheckBox;
27
+class TQComboBox;
28
+class TQLabel;
29
+class TQRadioButton;
30
+class TQSpinBox;
31
+class TrashImpl;
32
+
33
+class KTrashPropsWidget : public TQWidget
34
+{
35
+  Q_OBJECT
36
+
37
+  public:
38
+    KTrashPropsWidget(TQWidget *parent=0, const char *name=0);
39
+   ~KTrashPropsWidget();
40
+
41
+	  void load();
42
+	  void save();
43
+	  void setDefaultValues();
44
+
45
+	signals:
46
+		void changed(bool state);
47
+
48
+  protected slots:
49
+		void setDirty();
50
+    void percentSizeChanged(double);
51
+		void fixedSizeChanged(double);
52
+		void fixedSizeUnitActivated (int);
53
+		void rbPercentSizeToggled(bool);
54
+		void rbFixedSizeToggled(bool);
55
+    void trashChanged(int);
56
+    void useTypeChanged();
57
+
58
+  private:
59
+    void readConfig();
60
+    void writeConfig();
61
+    void setupGui();
62
+
63
+    TQCheckBox *mUseTimeLimit;
64
+    TQSpinBox  *mDays;
65
+    TQCheckBox *mUseSizeLimit;
66
+    int         mSizeLimitType;
67
+    TQRadioButton *mRbPercentSize, *mRbFixedSize;
68
+    KDoubleSpinBox *mPercentSize;
69
+    KDoubleSpinBox *mFixedSize;
70
+    TQComboBox *mFixedSizeUnit;
71
+    TQLabel    *mSizeLabel, *mLimitLabel;
72
+    TQComboBox *mLimitReachedAction;
73
+
74
+    TrashImpl *mTrashImpl;
75
+    TQString mCurrentTrash;
76
+    bool inhibitChangedSignal;
77
+
78
+    typedef struct {
79
+      bool useTimeLimit;
80
+      int days;
81
+      bool useSizeLimit;
82
+      int sizeLimitType;
83
+      double percent;
84
+      double fixedSize;
85
+      int fixedSizeUnit;
86
+      int actionType;
87
+    } ConfigEntry;
88
+
89
+    typedef TQMap<TQString, ConfigEntry> ConfigMap;
90
+    ConfigMap mConfigMap;
91
+};
92
+
93
+#endif

Loading…
Cancel
Save