summaryrefslogtreecommitdiffstats
path: root/src/app/configdialog.cpp
blob: 66b11e840f6b6946208a97ccc24c1b9b5b186d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// vim: set tabstop=4 shiftwidth=4 noexpandtab
// kate: indent-mode csands; indent-width 4; replace-tabs-save off; replace-tabs off; replace-trailing-space-save off; space-indent off; tabs-indents on; tab-width 4;
/*
Gwenview - A simple image viewer for KDE
Copyright 2000-2004 Aur�ien G�eau

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; either version 2
of the License, or (at your option) any later version.

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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/
// TQt 
#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <layout.h>
#include <tqlineedit.h>
#include <tqmap.h>
#include <tqradiobutton.h>
#include <tqspinbox.h>
#include <stylesheet.h>
#include <textedit.h>

// KDE
#include <kcolorbutton.h>
#include <kconfigdialogmanager.h>
#include <tdeversion.h>
#include <kdirsize.h>
#include <kfiledialog.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kio/netaccess.h>
#include <kmessagebox.h>
#include <kurllabel.h>
#include <kurlrequester.h>

#include <config.h>
// KIPI
#ifdef GV_HAVE_KIPI
#include <libkipi/pluginloader.h>
#endif

// Local 
#include "configfileoperationspage.h"
#include "configfullscreenpage.h"
#include "configimagelistpage.h"
#include "configimageviewpage.h"
#include "configmiscpage.h"
#include "configslideshowpage.h"
#include "gvcore/captionformatter.h"
#include "gvcore/filethumbnailview.h"
// This path is different because it's a generated file, so it's stored in builddir
#include <../gvcore/miscconfig.h>
#include <../gvcore/slideshowconfig.h>
#include <../gvcore/fileoperationconfig.h>
#include <../gvcore/fullscreenconfig.h>
#include <../gvcore/imageviewconfig.h>
#include <../gvcore/fileviewconfig.h>
#include "gvcore/thumbnailloadjob.h"

#include "configdialog.moc"
namespace Gwenview {

typedef TQValueList<KConfigDialogManager*> ConfigManagerList;

class ConfigDialogPrivate {
public:
	ConfigImageViewPage* mImageViewPage;
	ConfigImageListPage* mImageListPage;
	ConfigFullScreenPage* mFullScreenPage;
	ConfigFileOperationsPage* mFileOperationsPage;
	ConfigMiscPage* mMiscPage;
	ConfigSlideshowPage* mSlideShowPage;
#ifdef GV_HAVE_KIPI
	KIPI::ConfigWidget* mKIPIConfigWidget;
#endif

	ConfigManagerList mManagers;
};


// Two helper functions to create the config pages
template<class T>
void addConfigPage(KDialogBase* dialog, T* content, const TQString& header, const TQString& name, const char* iconName) {
	TQFrame* page=dialog->addPage(name, header, BarIcon(iconName, 32));
	content->reparent(page, TQPoint(0,0));
	TQVBoxLayout* layout=new TQVBoxLayout(page, 0, KDialog::spacingHint());
	layout->addWidget(content);
	layout->addStretch();
}

template<class T>
T* addConfigPage(KDialogBase* dialog, const TQString& header, const TQString& name, const char* iconName) {
	T* content=new T;
	addConfigPage(dialog, content, header, name, iconName);
	return content;
}


ConfigDialog::ConfigDialog(TQWidget* parent, KIPI::PluginLoader* pluginLoader)
: KDialogBase(
	KDialogBase::IconList,
	i18n("Configure"),
	KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply,
	KDialogBase::Ok,
	parent,
	"ConfigDialog",
	true,
	true)
{
	d=new ConfigDialogPrivate;

	// Create dialog pages
	d->mImageListPage = addConfigPage<ConfigImageListPage>(
		this, i18n("Configure Image List"), i18n("Image List"), "view_icon");
	d->mManagers << new KConfigDialogManager(d->mImageListPage, FileViewConfig::self());
	
	d->mImageViewPage = addConfigPage<ConfigImageViewPage>(
		this, i18n("Configure Image View"), i18n("Image View"), "looknfeel");
	d->mManagers << new KConfigDialogManager(d->mImageViewPage, ImageViewConfig::self());
	
	d->mFullScreenPage = addConfigPage<ConfigFullScreenPage>(
		this, i18n("Configure Full Screen Mode"), i18n("Full Screen"), "window_fullscreen");
	d->mManagers << new KConfigDialogManager(d->mFullScreenPage, FullScreenConfig::self());

	d->mFileOperationsPage = addConfigPage<ConfigFileOperationsPage>(
		this, i18n("Configure File Operations"), i18n("File Operations"), "folder");
	d->mManagers << new KConfigDialogManager(d->mFileOperationsPage, FileOperationConfig::self());

	d->mSlideShowPage = addConfigPage<ConfigSlideshowPage>(
		this, i18n("SlideShow"), i18n("SlideShow"), "slideshow_play");
	d->mManagers << new KConfigDialogManager(d->mSlideShowPage, SlideShowConfig::self());

#ifdef GV_HAVE_KIPI
	Q_ASSERT(pluginLoader);
	d->mKIPIConfigWidget = pluginLoader->configWidget(this);
	addConfigPage(
		this, d->mKIPIConfigWidget, i18n("Configure KIPI Plugins"), i18n("KIPI Plugins"), "kipi");
#else
	// Avoid "unused parameter" warning
	pluginLoader=pluginLoader;
#endif

	d->mMiscPage = addConfigPage<ConfigMiscPage>(
		this, i18n("Miscellaneous Settings"), i18n("Misc"), "gear");
	d->mManagers << new KConfigDialogManager(d->mMiscPage, MiscConfig::self());
	// Read config, because the modified behavior might have changed
	MiscConfig::self()->readConfig();

	// Image List tab
	int details=FileViewConfig::thumbnailDetails();
	d->mImageListPage->mShowFileName->setChecked(details & FileThumbnailView::FILENAME);
	d->mImageListPage->mShowFileDate->setChecked(details & FileThumbnailView::FILEDATE);
	d->mImageListPage->mShowFileSize->setChecked(details & FileThumbnailView::FILESIZE);
	d->mImageListPage->mShowImageSize->setChecked(details & FileThumbnailView::IMAGESIZE);

	connect(d->mImageListPage->mCalculateCacheSize,TQT_SIGNAL(clicked()),
		this,TQT_SLOT(calculateCacheSize()));
	connect(d->mImageListPage->mEmptyCache,TQT_SIGNAL(clicked()),
		this,TQT_SLOT(emptyCache()));

	// Image View tab
	d->mImageViewPage->mMouseWheelGroup->setButton(ImageViewConfig::mouseWheelScroll()?1:0);

	// Full Screen tab
	TQTextEdit* edit=d->mFullScreenPage->kcfg_osdFormat;
	edit->setMaximumHeight(edit->fontMetrics().height()*3);
	connect(edit, TQT_SIGNAL(textChanged()), TQT_SLOT(updateOSDPreview()) );

	// File Operations tab
	d->mFileOperationsPage->kcfg_destDir->fileDialog()->setMode(
		static_cast<KFile::Mode>(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly));

	d->mFileOperationsPage->mDeleteGroup->setButton(FileOperationConfig::deleteToTrash()?1:0);
	
	ConfigManagerList::Iterator it(d->mManagers.begin());
	for (;it!=d->mManagers.end(); ++it) {
		(*it)->updateWidgets();
	}
	updateOSDPreview();
}



ConfigDialog::~ConfigDialog() {
	delete d;
}


void ConfigDialog::slotOk() {
	slotApply();
	accept();
}


void ConfigDialog::slotApply() {
	bool needSignal=false;

	// Image List tab
	int details=
		(d->mImageListPage->mShowFileName->isChecked() ? FileThumbnailView::FILENAME : 0)
		| (d->mImageListPage->mShowFileDate->isChecked() ? FileThumbnailView::FILEDATE : 0)
		| (d->mImageListPage->mShowFileSize->isChecked() ? FileThumbnailView::FILESIZE : 0)
		| (d->mImageListPage->mShowImageSize->isChecked() ? FileThumbnailView::IMAGESIZE : 0)
		;
	if (details!=FileViewConfig::thumbnailDetails()) {
		FileViewConfig::setThumbnailDetails(details);
		needSignal=true;
	}
	
	// Image View tab
	ImageViewConfig::setMouseWheelScroll(
		d->mImageViewPage->mMouseWheelGroup->selected()==d->mImageViewPage->mMouseWheelScroll);

	// File Operations tab
	FileOperationConfig::setDeleteToTrash(
		d->mFileOperationsPage->mDeleteGroup->selected()==d->mFileOperationsPage->mDeleteToTrash);

	// KIPI tab
#ifdef GV_HAVE_KIPI
	d->mKIPIConfigWidget->apply();
#endif
	
	ConfigManagerList::Iterator it(d->mManagers.begin());
	for (;it!=d->mManagers.end(); ++it) {
		if ((*it)->hasChanged()) {
			needSignal=true;
		}
		(*it)->updateSettings();
	}
	if (needSignal) {
		emit settingsChanged();
	}
}


void ConfigDialog::calculateCacheSize() {
	KURL url;
	url.setPath(ThumbnailLoadJob::thumbnailBaseDir());
	unsigned long size=KDirSize::dirSize(url);
	KMessageBox::information( this,i18n("Cache size is %1").arg(KIO::convertSize(size)) );
}


void ConfigDialog::updateOSDPreview() {
	CaptionFormatter formatter;
	KURL url;
	url.setPath(i18n("/path/to/some/image.jpg"));
	formatter.mPath=url.path();
	formatter.mFileName=url.fileName();
	formatter.mComment=i18n("A comment");
	formatter.mImageSize=TQSize(1600, 1200);
	formatter.mPosition=4;
	formatter.mCount=12;
	formatter.mAperture="F2.8";
	formatter.mExposureTime="1/60 s";
	formatter.mIso="100";
	formatter.mFocalLength="8.88 mm";
	
	TQString txt=formatter.format( d->mFullScreenPage->kcfg_osdFormat->text() );
	d->mFullScreenPage->mOSDPreviewLabel->setText(txt);
}


void ConfigDialog::emptyCache() {
	TQString dir=ThumbnailLoadJob::thumbnailBaseDir();

	if (!TQFile::exists(dir)) {
		KMessageBox::information( this,i18n("Cache is already empty.") );
		return;
	}

	int response=KMessageBox::warningContinueCancel(this,
		"<qt>" + i18n("Are you sure you want to empty the thumbnail cache?"
		" This will delete the folder <b>%1</b>.").arg(TQStyleSheet::escape(dir)) + "</qt>",
		TQString(),
		KStdGuiItem::del());

	if (response==KMessageBox::Cancel) return;

	KURL url;
	url.setPath(dir);
	if (KIO::NetAccess::del(url, topLevelWidget()) ) {
		KMessageBox::information( this,i18n("Cache emptied.") );
	}
}


void ConfigDialog::onCacheEmptied(KIO::Job* job) {
	if ( job->error() ) {
		job->showErrorDialog(this);
		return;
	}
	KMessageBox::information( this,i18n("Cache emptied.") );
}

} // namespace