• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krdc

  • sources
  • kde-4.12
  • kdenetwork
  • krdc
  • config
hostpreferenceslist.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
4 **
5 ** This file is part of KDE.
6 **
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
11 **
12 ** This program 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
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
21 **
22 ****************************************************************************/
23 
24 #include "hostpreferenceslist.h"
25 #include "hostpreferences.h"
26 
27 #include <KDebug>
28 #include <KIcon>
29 #include <KLocale>
30 #include <KMessageBox>
31 #include <KPushButton>
32 #include <KStandardDirs>
33 
34 #include <QFile>
35 #include <QLayout>
36 #include <QListWidget>
37 
38 HostPreferencesList::HostPreferencesList(QWidget *parent, MainWindow *mainWindow, KConfigGroup hostPrefsConfig)
39  : QWidget(parent)
40  , m_hostPrefsConfig(hostPrefsConfig)
41  , m_mainWindow(mainWindow)
42 {
43  hostList = new QListWidget(this);
44  connect(hostList, SIGNAL(itemSelectionChanged()), SLOT(selectionChanged()));
45  connect(hostList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(configureHost()));
46 
47  configureButton = new KPushButton(this);
48  configureButton->setEnabled(false);
49  configureButton->setText(i18n("Configure..."));
50  configureButton->setIcon(KIcon("configure"));
51  connect(configureButton, SIGNAL(clicked()), SLOT(configureHost()));
52 
53  removeButton = new KPushButton(this);
54  removeButton->setEnabled(false);
55  removeButton->setText(i18n("Remove"));
56  removeButton->setIcon(KIcon("list-remove"));
57  connect(removeButton, SIGNAL(clicked()), SLOT(removeHost()));
58 
59  QVBoxLayout *buttonLayout = new QVBoxLayout;
60  buttonLayout->addWidget(configureButton);
61  buttonLayout->addWidget(removeButton);
62  buttonLayout->addStretch();
63 
64  QHBoxLayout *mainLayout = new QHBoxLayout(this);
65  mainLayout->addWidget(hostList);
66  mainLayout->addLayout(buttonLayout);
67 
68  setLayout(mainLayout);
69 
70  readConfig();
71 }
72 
73 HostPreferencesList::~HostPreferencesList()
74 {
75 }
76 
77 void HostPreferencesList::readConfig()
78 {
79  QStringList urls = m_hostPrefsConfig.groupList();
80 
81  for (int i = 0; i < urls.size(); ++i)
82  hostList->addItem(new QListWidgetItem(urls.at(i)));
83 }
84 
85 void HostPreferencesList::saveSettings()
86 {
87  m_hostPrefsConfig.sync();
88 }
89 
90 void HostPreferencesList::configureHost()
91 {
92  QList<QListWidgetItem *> selectedItems = hostList->selectedItems();
93 
94  foreach(QListWidgetItem *selectedItem, selectedItems) {
95  const QString url = selectedItem->text();
96 
97  kDebug(5010) << "Configure host: " << url;
98 
99  HostPreferences* prefs = 0;
100 
101  const QList<RemoteViewFactory *> remoteViewFactories(m_mainWindow->remoteViewFactoriesList());
102  foreach(RemoteViewFactory *factory, remoteViewFactories) {
103  if (factory->supportsUrl(url)) {
104  prefs = factory->createHostPreferences(m_hostPrefsConfig.group(url), this);
105  if (prefs) {
106  kDebug(5010) << "Found plugin to handle url (" + url + "): " + prefs->metaObject()->className();
107  } else {
108  kDebug(5010) << "Found plugin to handle url (" + url + "), but plugin does not provide preferences";
109  }
110  }
111  }
112 
113  if (prefs) {
114  prefs->showDialog(this);
115  delete prefs;
116  } else {
117  KMessageBox::error(this,
118  i18n("The selected host cannot be handled."),
119  i18n("Unusable URL"));
120  }
121  }
122 }
123 
124 void HostPreferencesList::removeHost()
125 {
126  const QList<QListWidgetItem *> selectedItems = hostList->selectedItems();
127 
128  foreach(QListWidgetItem *selectedItem, selectedItems) {
129  kDebug(5010) << "Remove host: " << selectedItem->text();
130 
131  m_hostPrefsConfig.deleteGroup(selectedItem->text());
132  delete(selectedItem);
133  }
134 
135  saveSettings();
136  hostList->clearSelection();
137 }
138 
139 void HostPreferencesList::selectionChanged()
140 {
141  const bool enabled = hostList->selectedItems().isEmpty() ? false : true;
142 
143  configureButton->setEnabled(enabled);
144  removeButton->setEnabled(enabled);
145 }
146 
147 #include "hostpreferenceslist.moc"
HostPreferencesList::~HostPreferencesList
~HostPreferencesList()
Definition: hostpreferenceslist.cpp:73
hostpreferences.h
HostPreferences::showDialog
bool showDialog(QWidget *parent)
Show the configuration dialog.
Definition: hostpreferences.cpp:177
hostpreferenceslist.h
QWidget
RemoteViewFactory::createHostPreferences
virtual HostPreferences * createHostPreferences(KConfigGroup configGroup, QWidget *parent)=0
Returns a new HostPreferences implementing object or 0 if no settings are available.
HostPreferences
Definition: hostpreferences.h:42
RemoteViewFactory::supportsUrl
virtual bool supportsUrl(const KUrl &url) const =0
Returns true if the provided url is supported by the current plugin.
HostPreferencesList::HostPreferencesList
HostPreferencesList(QWidget *parent, MainWindow *mainWindow, KConfigGroup hostPrefsConfig)
Definition: hostpreferenceslist.cpp:38
RemoteViewFactory
Factory to be implemented by any plugin.
Definition: remoteviewfactory.h:52
MainWindow::remoteViewFactoriesList
QList< RemoteViewFactory * > remoteViewFactoriesList() const
Definition: mainwindow.cpp:1167
MainWindow
Definition: mainwindow.h:55
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krdc

Skip menu "krdc"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal