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

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
  • settings
structuresmanagerview.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten Framework, made within the KDE community.
3 
4  Copyright 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5  Copyright 2009, 2012 Alex Richardson <alex.richardson@gmx.de>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) version 3, or any
11  later version accepted by the membership of KDE e.V. (or its
12  successor approved by the membership of KDE e.V.), which shall
13  act as a proxy defined in Section 6 of version 3 of the license.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "structuresmanagerview.h"
25 #include "structureaddremovewidget.h"
26 
27 #include "structviewpreferences.h"
28 #include "../structuresmanager.h"
29 #include "../structtool.h"
30 // KDE
31 #include <KFileDialog>
32 #include <KStandardDirs>
33 #include <KIO/NetAccess>
34 #include <KMessageBox>
35 #include <KPluginSelector>
36 #include <KConfigDialogManager>
37 #include <KPluginInfo>
38 #include <KPushButton>
39 #include <KDialog>
40 //KNS
41 #include <KNS3/KNewStuffButton>
42 // Qt
43 #include <QtGui/QListWidgetItem>
44 #include <QtGui/QLayout>
45 #include <QtGui/QSizePolicy>
46 #include <KDebug>
47 
48 static const int FileNameRole = Qt::UserRole;
49 
50 StructuresManagerView::StructuresManagerView(Kasten2::StructTool* tool, QWidget* parent)
51  : QWidget(parent), mTool(tool), mStructuresSelector(0), mRebuildingPluginsList(false)
52 {
53  KConfigDialogManager::changedMap()->insert(QLatin1String("StructuresManagerView"), SIGNAL(changed(QStringList)));
54  setObjectName(QLatin1String("kcfg_LoadedStructures"));
55  mSelectedStructures = Kasten2::StructViewPreferences::loadedStructures();
56 
57  QVBoxLayout* pageLayout = new QVBoxLayout();
58  setLayout(pageLayout);
59 
60  rebuildPluginSelectorEntries();
61 
62 
63  QHBoxLayout* buttonsLayout = new QHBoxLayout();
64  pageLayout->addLayout(buttonsLayout);
65 
66  mGetNewStructuresButton = new KNS3::Button(i18n("Get New Structures..."),
67  QLatin1String("okteta-structures.knsrc"), this);
68  connect(mGetNewStructuresButton, SIGNAL(dialogFinished(KNS3::Entry::List)),
69  SLOT(onGetNewStructuresClicked(KNS3::Entry::List)));
70  buttonsLayout->addWidget(mGetNewStructuresButton);
71 
72  mAdvancedSelectionButton = new KPushButton(KIcon(QLatin1String("configure")), i18n("Advanced Selection..."), this);
73  connect(mAdvancedSelectionButton, SIGNAL(clicked()), SLOT(advancedSelection()));
74  buttonsLayout->addWidget(mAdvancedSelectionButton);
75 }
76 
77 void StructuresManagerView::onGetNewStructuresClicked(const KNS3::Entry::List& changedEntries)
78 {
79  foreach (const KNS3::Entry& e, changedEntries)
80  {
81  kDebug() << "Changed Entry: " << e.name();
82  if (e.status() == KNS3::Entry::Installed)
83  {
84  //new element installed
85  kDebug() << "installed files:" << e.installedFiles();
86  }
87  if (e.status() == KNS3::Entry::Deleted)
88  {
89  //element uninstalled
90  kDebug() << "deleted files:" << e.uninstalledFiles();
91  }
92  }
93  if (!changedEntries.isEmpty())
94  {
95  kDebug() << "installed structures changed -> rebuilding list of installed structures";
96  mTool->manager()->reloadPaths();
97  rebuildPluginSelectorEntries();
98  }
99 }
100 
101 QStringList StructuresManagerView::values()
102 {
103  return mSelectedStructures;
104 }
105 
106 
107 void StructuresManagerView::advancedSelection()
108 {
109  StructureAddRemoveWidget* advancedSelectionWidget = new StructureAddRemoveWidget(mSelectedStructures, mTool, this);
110  QPointer<KDialog> dlg = new KDialog(this); //the dlg-on-heap-variant
111  dlg->setMainWidget(advancedSelectionWidget);
112  if (dlg->exec() == QDialog::Accepted) {
113  QStringList newVals = advancedSelectionWidget->values();
114  if (newVals != mSelectedStructures) {
115  kDebug() << "selection changed from " << mSelectedStructures << "to" << newVals;
116  mSelectedStructures = newVals;
117  emit changed(newVals);
118  }
119  }
120  delete dlg;
121 }
122 
123 void StructuresManagerView::onPluginSelectorChange(bool change)
124 {
125  if (mRebuildingPluginsList)
126  return;
127  kDebug() << "pluginselector changed: " << change;
128  if (!change)
129  return;
130  mStructuresSelector->save();
131  reloadSelectedItems();
132 }
133 
134 void StructuresManagerView::reloadSelectedItems() {
135  QStringList newVals;
136  foreach(const Kasten2::StructureDefinitionFile* def, mTool->manager()->structureDefs())
137  {
138  KPluginInfo info = def->pluginInfo();
139  if (info.isPluginEnabled())
140  newVals.append(QString(QLatin1String("\'%1\':\'*\'")).arg(info.pluginName()));
141  }
142  if (newVals != mSelectedStructures) {
143  kDebug() << "selection changed from " << mSelectedStructures << "to" << newVals;
144  mSelectedStructures = newVals;
145  emit changed(newVals);
146  }
147  else {
148  kDebug() << "no change:" << mSelectedStructures;
149  }
150 }
151 
152 void StructuresManagerView::rebuildPluginSelectorEntries()
153 {
154  mRebuildingPluginsList = true;
155  QStringList newVals;
156  KPluginInfo::List plugins;
157  KPluginInfo::List dynamicPlugins;
158  foreach(const Kasten2::StructureDefinitionFile* def, mTool->manager()->structureDefs())
159  {
160  KPluginInfo info = def->pluginInfo();
161  if (info.category() == QLatin1String("structure"))
162  plugins.append(info);
163  else if (info.category() == QLatin1String("structure/js"))
164  dynamicPlugins.append(info);
165  }
166 
167  //XXX is there any way to clear the plugins selector?
168  QBoxLayout* layoutObj = qobject_cast<QBoxLayout*>(layout());
169  Q_CHECK_PTR(layoutObj);
170  if (mStructuresSelector)
171  {
172  layoutObj->removeWidget(mStructuresSelector);
173  delete mStructuresSelector;
174  }
175  mStructuresSelector = new KPluginSelector(this);
176  connect(mStructuresSelector, SIGNAL(changed(bool)),
177  SLOT(onPluginSelectorChange(bool)));
178  layoutObj->insertWidget(0, mStructuresSelector);
179 
180  mStructuresSelector->addPlugins(plugins, KPluginSelector::ReadConfigFile, i18n(
181  "Structure Definitions"), QLatin1String("structure"), mTool->manager()->config());
182  mStructuresSelector->addPlugins(dynamicPlugins, KPluginSelector::ReadConfigFile,
183  i18n("Dynamic Structure Definitions"), QLatin1String("structure/js"),
184  mTool->manager()->config());
185  mStructuresSelector->load();
186  mStructuresSelector->updatePluginsState();
187  mRebuildingPluginsList = false;
188  reloadSelectedItems();
189 }
190 
191 StructuresManagerView::~StructuresManagerView()
192 {
193 }
StructuresManagerView::onPluginSelectorChange
void onPluginSelectorChange(bool change)
Definition: structuresmanagerview.cpp:123
StructuresManagerView::advancedSelection
void advancedSelection()
Definition: structuresmanagerview.cpp:107
Kasten2::StructureDefinitionFile
This class takes care of all the XML parsing and stores the result.
Definition: structuredefinitionfile.h:43
QWidget
structviewpreferences.h
FileNameRole
static const int FileNameRole
Definition: structuresmanagerview.cpp:48
KDialog
Kasten2::StructuresManager::structureDefs
const QList< StructureDefinitionFile * > structureDefs() const
Definition: structuresmanager.h:53
structuresmanagerview.h
StructuresManagerView::onGetNewStructuresClicked
void onGetNewStructuresClicked(const KNS3::Entry::List &changedEntries)
Definition: structuresmanagerview.cpp:77
StructuresManagerView::StructuresManagerView
StructuresManagerView(Kasten2::StructTool *manager, QWidget *parent=0)
Definition: structuresmanagerview.cpp:50
StructuresManagerView::changed
void changed(QStringList newValues)
StructuresManagerView::~StructuresManagerView
virtual ~StructuresManagerView()
Definition: structuresmanagerview.cpp:191
Kasten2::StructuresManager::config
KSharedConfig::Ptr config() const
Definition: structuresmanager.h:58
structureaddremovewidget.h
Kasten2::StructuresManager::reloadPaths
void reloadPaths()
Definition: structuresmanager.cpp:46
StructureAddRemoveWidget::values
QStringList values() const
Definition: structureaddremovewidget.h:69
StructureAddRemoveWidget
Definition: structureaddremovewidget.h:36
Kasten2::StructViewPreferences::loadedStructures
static QStringList loadedStructures()
Get LoadedStructures.
Definition: structviewpreferences.h:289
Kasten2::StructureDefinitionFile::pluginInfo
const KPluginInfo & pluginInfo() const
Definition: structuredefinitionfile.h:68
Kasten2::StructTool::manager
StructuresManager * manager() const
Definition: structtool.cpp:436
StructuresManagerView::values
QStringList values()
Kasten2::StructTool
Definition: structtool.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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