aboutsummaryrefslogtreecommitdiffstats
path: root/kde2/plugins/plpprops.cc
blob: 1992e33950d26369c26a0a38dc7b451ca2a3e321 (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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stream.h>
#include <errno.h>
#include <assert.h>

#include <qfile.h>
#include <qapplication.h>
#include <qdir.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qstrlist.h>
#include <qstringlist.h>
#include <qtextstream.h>
#include <qpainter.h>
#include <qlayout.h>
#include <qcombobox.h>
#include <qgroupbox.h>

#include <kdialog.h>
#include <kdirsize.h>
#include <kdirwatch.h>
#include <kdebug.h>
#include <kdesktopfile.h>
#include <kicondialog.h>
#include <kurl.h>
#include <kurlrequester.h>
#include <klocale.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <kstddirs.h>
#include <kio/job.h>
#include <kio/renamedlg.h>
#include <kfiledialog.h>
#include <kmimetype.h>
#include <kmessagebox.h>
#include <kservice.h>
#include <kglobal.h>
#include <kcompletion.h>
#include <klineedit.h>
//#include <klibloader.h>
//#include <ktrader.h>
#include <kio/slaveinterface.h>

#include "plpprops.h"
#include "pie3dwidget.h"

#include <qobjectlist.h>
#include <qtabwidget.h>

#define KIO_ARGS QByteArray packedArgs; \
QDataStream stream( packedArgs, IO_WriteOnly ); stream

class PlpPropsPlugin::PlpPropsPluginPrivate {
public:
	PlpPropsPluginPrivate() { }
	~PlpPropsPluginPrivate() { }

	QFrame *m_frame;
};

/*
 * A VERY UGLY HACK for removing the Permissions-Page from
 * the Properties dialog.
 */
static void
removePermsPage(QWidget *theDialog) {
	QObject *qtabwidget = 0L;
	QFrame *permframe = 0L;

	//
	// First, find the QTabWidget in the dialog.
	// This is easy, cause there's only one.
	//
	QObjectList *l = theDialog->queryList("QTabWidget");
	QObjectListIt it(*l);
	QObject * obj;
	while ((obj=it.current()) != 0) {
		++it;
		qtabwidget = obj;
	}
	delete l;

	// Now, walk thru all Childs of the QTabWidget which are
	// inherited from class QFrame.
	//
	if (qtabwidget != 0L) {
		l = qtabwidget->queryList("QFrame");
		QObjectListIt it(*l);

		while ((obj = it.current()) != 0) {
			QObjectList *l2 = obj->queryList();
			QObjectListIt it2(*l2);
			QObject *o2;
			int qvbl, qgb, qgl, ql, qcb;
			qvbl = qgb = qgl = ql = qcb = 0;

			// If we found a QFrame, count it's children
			// by className. We must rely on the numbers,
			// because not a single child has been given
			// a name.
			while ((o2 = it2.current()) != 0) {
				if (o2->isA("QVBoxLayout"))
					qvbl++;
				if (o2->isA("QGroupBox"))
					qgb++;
				if (o2->isA("QGridLayout"))
					qgl++;
				if (o2->isA("QLabel"))
					ql++;
				if (o2->isA("QCheckBox"))
					qcb++;
				++it2;
			}
			delete l2;

			// The PermissionsPage is build out of:
			//
			// 1 QVBoxLayout, 2 QGroupboxes, 2 QGridLayouts,
			// 15 QLabels and 12 QCheckBoxes
			//
			if ((qvbl == 1) &&
			    (qgb == 2) &&
			    (qgl == 2) &&
			    (ql == 15) &&
			    (qcb == 12)) {
				permframe = (QFrame *)obj;
				break;
			}
			++it;
		}
		delete l;

		// If we found it, remove it.
		if (permframe != 0)
			((QTabWidget *)qtabwidget)->removePage(permframe);
	}
}

PlpPropsPlugin::PlpPropsPlugin(KPropertiesDialog *_props)
	: KPropsDlgPlugin( _props )
{
	d = new PlpPropsPluginPrivate;
	bool removePerms = false;
	
	if (!supports(properties->items()))
		return;

	if (PlpFileAttrPage::supports(properties->items())) {
		PlpFileAttrPage *p = new PlpFileAttrPage(_props);
		removePerms = true;
	}
	if (PlpDriveAttrPage::supports(properties->items())) {
		PlpDriveAttrPage *p = new PlpDriveAttrPage(_props);
		removePerms = true;
	}
	if (PlpMachinePage::supports(properties->items())) {
		PlpMachinePage *p = new PlpMachinePage(_props);
	}
	if (PlpOwnerPage::supports(properties->items())) {
		PlpOwnerPage *p = new PlpOwnerPage(_props);
	}
	if (removePerms)
		removePermsPage(properties->dialog());
}

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

bool PlpPropsPlugin::supports(KFileItemList _items) {
	for (KFileItemListIterator it(_items); it.current(); ++it) {
		KFileItem *fi = it.current();

		if (fi->url().protocol() != QString::fromLatin1("psion"))
			return false;
	}
	return true;
}

void PlpPropsPlugin::applyChanges() {
	kdDebug(250) << "PlpFileAttrPlugin::applyChanges" << endl;
}

void PlpPropsPlugin::postApplyChanges() {
}

class PlpFileAttrPage::PlpFileAttrPagePrivate {
public:
	PlpFileAttrPagePrivate() { }
	~PlpFileAttrPagePrivate() { }

	QFrame *m_frame;
};

PlpFileAttrPage::PlpFileAttrPage(KPropertiesDialog *_props)
	: KPropsDlgPlugin( _props ) {
	d = new PlpFileAttrPagePrivate;
	d->m_frame = properties->dialog()->addPage(i18n("Psion &Attributes"));
}

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

bool PlpFileAttrPage::supports(KFileItemList _items) {
	for (KFileItemListIterator it(_items); it.current(); ++it) {
		KFileItem *fi = it.current();

		QString path = fi->url().path(-1);
		if (path.contains('/') == 1)
			return false;
	}
	return true;
}

void PlpFileAttrPage::applyChanges() {
}

class PlpDriveAttrPage::PlpDriveAttrPagePrivate {
public:
	PlpDriveAttrPagePrivate() { }
	~PlpDriveAttrPagePrivate() { }

	QFrame *m_frame;
};

PlpDriveAttrPage::PlpDriveAttrPage(KPropertiesDialog *_props)
	: KPropsDlgPlugin( _props ) {

	d = new PlpDriveAttrPagePrivate;
	d->m_frame = properties->dialog()->addPage(i18n("Psion &Drive"));

	QBoxLayout *box = new QVBoxLayout( d->m_frame, KDialog::spacingHint() );
	QLabel *l;
	QGridLayout *gl;
	usedColor = QColor(219, 58, 197);
	freeColor = QColor(39, 56, 167);

	KIO_ARGS << int(1) << properties->item()->name();
	KIO::StatJob *job = new KIO::StatJob(KURL("psion:/"), KIO::CMD_SPECIAL, packedArgs, false);
	connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotSpecialFinished(KIO::Job *)));

	gb = new QGroupBox(i18n("Information"), d->m_frame);
	box->addWidget(gb);

	gl = new QGridLayout(gb, 7, 4, 15);
	gl->addRowSpacing(0, 10);

	l = new QLabel(i18n("Type"), gb, "typeLabel");
	gl->addWidget(l, 1, 0);

	typeLabel = new QLabel(gb);
	gl->addWidget(typeLabel, 2, 0);

	l = new QLabel(i18n("Total capacity"), gb, "capacityLabel");
	gl->addWidget (l, 1, 1);

	totalLabel = new QLabel(i18n(" "), gb, "capacityValue");
	gl->addWidget(totalLabel, 2, 1);

	l = new QLabel(i18n("Free space"), gb, "spaceLabel");
	gl->addWidget (l, 1, 2);

	freeLabel = new QLabel(i18n(" "), gb, "spaceValue");
	gl->addWidget(freeLabel, 2, 2);

	l = new QLabel(i18n("Unique ID"), gb, "uidLabel");
	gl->addWidget (l, 1, 3);

	uidLabel = new QLabel(i18n(" "), gb, "uidValue");
	gl->addWidget(uidLabel, 2, 3);

	pie = new Pie3DWidget(gb, "pie");

	gl->addMultiCellWidget(pie, 3, 4, 1, 2);

	l = new QLabel(i18n("Used space:"), gb, "usedLgend");
	l->setAlignment(AlignRight | AlignVCenter);
	gl->addWidget (l, 5, 2);
	
	l = new QLabel(i18n(" "), gb, "usedLegendColor");
	l->setBackgroundColor(usedColor);
	gl->addWidget (l, 5, 3);

	l = new QLabel(i18n("Free space:"), gb, "spaceLegend");
	l->setAlignment(AlignRight | AlignVCenter);
	gl->addWidget (l, 6, 2);

	l = new QLabel(i18n(" "), gb, "spaceLegendColor");
	l->setBackgroundColor(freeColor);

	gl->addWidget (l, 6, 3);

	box->addStretch(10);
}

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

bool PlpDriveAttrPage::supports(KFileItemList _items) {
	for (KFileItemListIterator it(_items); it.current(); ++it) {
		KFileItem *fi = it.current();

		QString path = fi->url().path(-1);
		if (path.contains('/') != 1)
			return false;
	}
	return true;
}

void PlpDriveAttrPage::applyChanges() {
}

void PlpDriveAttrPage::slotSpecialFinished(KIO::Job *job) {
	KIO::StatJob *sJob = static_cast<KIO::StatJob *>(job);

	if (sJob->error())
		job->showErrorDialog(properties->dialog());
	else {
		KIO::UDSEntry e = sJob->statResult();
		bool total_found = false;
		bool free_found = false;

		for (KIO::UDSEntry::ConstIterator it = e.begin(); it != e.end(); ++it) {
			if ((*it).m_uds == KIO::UDS_SIZE) {
				total_found = true;
				total = (unsigned long)((*it).m_long);
			}
			if ((*it).m_uds == KIO::UDS_MODIFICATION_TIME) {
				free_found = true;
				unused = (unsigned long)((*it).m_long);
			}
			if ((*it).m_uds == KIO::UDS_CREATION_TIME) {
				unsigned long uid = (unsigned long)((*it).m_long);
				uidLabel->setText(QString::fromLatin1("%1").arg(uid, 8, 16));
			}
			if ((*it).m_uds == KIO::UDS_NAME) {
				QString name = ((*it).m_str);
				typeLabel->setText(name);
			}
			if ((*it).m_uds == KIO::UDS_USER) {
				QString name = ((*it).m_str);
				gb->setTitle(QString(i18n("Information for Psion drive %1: (%2)")).arg(name).arg(properties->item()->name()));
			}
		}
		if (total_found && free_found) {
			totalLabel->setText(QString::fromLatin1("%1 (%2)").arg(KIO::convertSize(total)).arg(KGlobal::locale()->formatNumber(total, 0)));
			freeLabel->setText(QString::fromLatin1("%1 (%2)").arg(KIO::convertSize(unused)).arg(KGlobal::locale()->formatNumber(unused, 0)));
			pie->addPiece(total - unused, usedColor);
			pie->addPiece(unused, freeColor);
		}
	}
}

class PlpMachinePage::PlpMachinePagePrivate {
public:
	PlpMachinePagePrivate() { }
	~PlpMachinePagePrivate() { }

	QFrame *m_frame;
};

PlpMachinePage::PlpMachinePage( KPropertiesDialog *_props )
	: KPropsDlgPlugin( _props ) {

	d = new PlpMachinePagePrivate;
	d->m_frame = properties->dialog()->addPage(i18n("Psion &Machine"));

	QVBoxLayout * mainlayout = new QVBoxLayout( d->m_frame, KDialog::spacingHint());

	// Now the widgets in the top layout

	QLabel* l;
	l = new QLabel(d->m_frame, "Label_1" );
	l->setText( i18n("Machine UID:") );
	mainlayout->addWidget(l, 1);

	mainlayout->addStretch(2);
}

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

bool PlpMachinePage::supports(KFileItemList _items) {
	for (KFileItemListIterator it(_items); it.current(); ++it) {
		KFileItem *fi = it.current();

		QString path = fi->url().path(-1);
		if (path.contains('/') != 1)
			return false;
		if (fi->mimetype() != QString::fromLatin1("application/x-psion-machine"))
			return false;
	}
	return true;
}

void PlpMachinePage::applyChanges() {
}


class PlpOwnerPage::PlpOwnerPagePrivate
{
public:
	PlpOwnerPagePrivate()	{ }
	~PlpOwnerPagePrivate() { }

	QFrame *m_frame;
};

PlpOwnerPage::PlpOwnerPage( KPropertiesDialog *_props ) : KPropsDlgPlugin( _props ) {
	d = new PlpOwnerPagePrivate;
	d->m_frame = properties->dialog()->addPage(i18n("Psion &Owner"));
}

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

bool PlpOwnerPage::supports(KFileItemList _items) {
	for (KFileItemListIterator it(_items); it.current(); ++it) {
		KFileItem *fi = it.current();

		QString path = fi->url().path(-1);
		if (path.contains('/') != 1)
			return false;
		if (fi->mimetype() != QString::fromLatin1("application/x-psion-owner"))
			return false;
	}
	return true;
}

void PlpOwnerPage::applyChanges() {
}

#include "plpprops.moc"