summaryrefslogtreecommitdiffstats
path: root/kcontrol/hwmanager/deviceiconview.cpp
blob: 44a71b3a346ead322ec1263e32843757eafc15e6 (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
/*
  Copyright (c) 2000 Matthias Elter <elter@kde.org>
  Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>

  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.

*/

#include <tqheader.h>
#include <tqcursor.h>

#include <tdelocale.h>
#include <kstandarddirs.h>
#include <kservicegroup.h>
#include <kiconloader.h>
#include <tdemessagebox.h>

#include <kdebug.h>

#include "deviceiconview.h"
#include "deviceiconview.moc"

DeviceIconView::DeviceIconView(TQWidget * parent, const char * name)
	: TDEListView(parent, name)
{
	setSorting(0, true);
	addColumn(TQString::null);
	
	// Show expand/collapse widgets on root items
	setRootIsDecorated(true);
	
	header()->hide();
	
	connect(this, TQT_SIGNAL(clicked(TQListViewItem*)), this, TQT_SLOT(slotItemSelected(TQListViewItem*)));
	connect(this, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotItemDoubleClicked(TQListViewItem*)));
}

void DeviceIconView::slotItemSelected(TQListViewItem* item)
{
	TQApplication::restoreOverrideCursor();
	if (!item) {
		return;
	}
}

void DeviceIconView::slotItemDoubleClicked(TQListViewItem* item)
{
	TQApplication::restoreOverrideCursor();
	if (!item) {
		return;
	}

	DeviceIconItem* divi = dynamic_cast<DeviceIconItem*>(item);
	if (!divi) {
		return;
	}

	if (divi->device()) {
		DevicePropertiesDialog* propsDlg = new DevicePropertiesDialog(divi->device(), this);
		propsDlg->exec();
		delete propsDlg;
	}
	else {
		KMessageBox::sorry(this, i18n("Detailed information is not available for this device"),
		                   i18n("Information Unavailable"));
	}
}

void DeviceIconView::keyPressEvent(TQKeyEvent *e)
{
	if (e->key() == Key_Return
		|| e->key() == Key_Enter
		|| e->key() == Key_Space)
	{
		if (currentItem()) {
			slotItemSelected(currentItem());
		}
	}
	else {
		TDEListView::keyPressEvent(e);
	}
}

TQPixmap DeviceIconView::loadIcon( const TQString &name )
{
	TQPixmap icon = DesktopIcon( name, iconSize() );
	
	if(icon.isNull()) {
		icon = DesktopIcon( "misc", iconSize() );
	}
	
	return icon;
}

TDEIcon::StdSizes DeviceIconView::iconSize() {
	return TDEIcon::SizeSmall;
}