2015-02-07 00:32:25 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008-2010 by Volker Lanz <vl@fidra.de> *
|
2016-03-02 18:33:40 +00:00
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2015-02-07 00:32:25 +00:00
|
|
|
* *
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
2010-01-28 16:27:28 +00:00
|
|
|
|
|
|
|
#include "gui/listdevices.h"
|
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <core/device.h>
|
2010-01-28 16:27:28 +00:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <util/globallog.h>
|
|
|
|
#include <util/capacity.h>
|
2010-01-28 16:27:28 +00:00
|
|
|
|
2015-04-09 21:26:40 +01:00
|
|
|
#include <KIconLoader>
|
2010-01-28 16:27:28 +00:00
|
|
|
|
2010-02-12 11:29:12 +00:00
|
|
|
class ListDeviceWidgetItem : public QListWidgetItem
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
public:
|
|
|
|
ListDeviceWidgetItem(const Device& d) :
|
|
|
|
QListWidgetItem(QIcon::fromTheme(d.iconName()).pixmap(IconSize(KIconLoader::Desktop)), d.prettyName()),
|
|
|
|
deviceNode(d.deviceNode()) {
|
|
|
|
setToolTip(d.prettyName());
|
|
|
|
setSizeHint(QSize(0, 32));
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString deviceNode;
|
2010-02-12 11:29:12 +00:00
|
|
|
};
|
|
|
|
|
2010-01-28 16:27:28 +00:00
|
|
|
/** Creates a new ListDevices instance.
|
2015-07-13 15:17:41 +01:00
|
|
|
@param parent the parent widget
|
2010-01-28 16:27:28 +00:00
|
|
|
*/
|
|
|
|
ListDevices::ListDevices(QWidget* parent) :
|
2015-07-13 15:17:41 +01:00
|
|
|
QWidget(parent),
|
|
|
|
Ui::ListDevicesBase(),
|
2016-04-14 19:18:36 +01:00
|
|
|
m_ActionCollection(nullptr)
|
2010-01-28 16:27:28 +00:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
setupUi(this);
|
2010-01-28 16:27:28 +00:00
|
|
|
}
|
|
|
|
|
2010-02-19 21:25:48 +00:00
|
|
|
void ListDevices::updateDevices(OperationStack::Devices& devices)
|
2010-01-28 16:27:28 +00:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
listDevices().clear();
|
2010-01-28 16:27:28 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
foreach(const Device * d, devices)
|
|
|
|
listDevices().addItem(new ListDeviceWidgetItem(*d));
|
2010-01-28 16:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ListDevices::on_m_ListDevices_itemSelectionChanged()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
if (listDevices().selectedItems().size() == 1) {
|
|
|
|
ListDeviceWidgetItem* item = dynamic_cast<ListDeviceWidgetItem*>(listDevices().selectedItems()[0]);
|
2010-01-28 16:27:28 +00:00
|
|
|
|
2016-04-14 19:18:36 +01:00
|
|
|
if (item != nullptr)
|
2015-07-13 15:17:41 +01:00
|
|
|
emit selectionChanged(item->deviceNode);
|
|
|
|
}
|
2010-01-28 16:27:28 +00:00
|
|
|
}
|
|
|
|
|
2010-02-19 21:09:14 +00:00
|
|
|
void ListDevices::on_m_ListDevices_itemDoubleClicked(QListWidgetItem* list_item)
|
2010-02-17 13:18:25 +00:00
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
ListDeviceWidgetItem* item = dynamic_cast<ListDeviceWidgetItem*>(list_item);
|
2010-02-17 13:18:25 +00:00
|
|
|
|
2016-04-14 19:18:36 +01:00
|
|
|
if (item != nullptr)
|
2015-07-13 15:17:41 +01:00
|
|
|
emit deviceDoubleClicked(item->deviceNode);
|
2010-02-17 13:18:25 +00:00
|
|
|
}
|
2010-02-23 16:30:05 +00:00
|
|
|
|
|
|
|
bool ListDevices::setSelectedDevice(const QString& device_node)
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
QList<QListWidgetItem*> items = listDevices().findItems(device_node, Qt::MatchContains);
|
2010-02-23 16:30:05 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
if (items.size() > 0) {
|
|
|
|
listDevices().setCurrentItem(items[0]);
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-23 16:30:05 +00:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
return false;
|
2010-02-23 16:30:05 +00:00
|
|
|
}
|