• 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
  • viewprofiles
viewprofilesmanagedialog.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2010,2012 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "viewprofilesmanagedialog.h"
24 
25 // this
26 #include "viewprofileeditdialog.h"
27 #include "viewprofiletablemodel.h"
28 // Okteta Gui Kasten
29 #include <bytearrayviewprofilemanager.h>
30 #include <bytearrayviewprofilelock.h>
31 // KDE
32 #include <KPushButton>
33 #include <KLocale>
34 // Qt
35 #include <QtGui/QHBoxLayout>
36 #include <QtGui/QTreeView>
37 #include <QtGui/QItemSelectionModel>
38 
39 
40 namespace Kasten2
41 {
42 
43 ViewProfilesManageDialog::ViewProfilesManageDialog( ByteArrayViewProfileManager* viewProfileManager,
44  QWidget* parent )
45  : KDialog( parent )
46  , mViewProfileManager( viewProfileManager )
47  , mCurrentViewProfileId()
48 {
49  setCaption( i18nc("@title:window", "View Profiles") );
50 
51  QWidget* page = new QWidget( this );
52  setMainWidget( page );
53 
54  QHBoxLayout* pageLayout = new QHBoxLayout( page );
55 
56  // profile list
57  mViewProfileTableView = new QTreeView( page );
58  mViewProfileTableModel = new ViewProfileTableModel( mViewProfileManager, this );
59  mViewProfileTableView->setObjectName( QLatin1String("ViewProfileTableView") );
60  mViewProfileTableView->setHeaderHidden( true );
61  mViewProfileTableView->setRootIsDecorated( false );
62  mViewProfileTableView->setItemsExpandable( false );
63  mViewProfileTableView->setUniformRowHeights( true );
64  mViewProfileTableView->setAllColumnsShowFocus( true );
65  mViewProfileTableView->setModel( mViewProfileTableModel );
66  connect( mViewProfileTableView->selectionModel(),
67  SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
68  SLOT(onViewProfileSelectionChanged()) );
69  connect( mViewProfileTableModel, SIGNAL(modelReset()),
70  SLOT(onModelReset()) );
71 
72  // buttons
73  QVBoxLayout* buttonLayout = new QVBoxLayout;
74  KPushButton* createButton = // copy from selected
75  new KPushButton(
76  KGuiItem(i18nc("@action:button",
77  "&Create new..."),
78  QLatin1String("document-new"),
79  i18nc("@info:tooltip",
80  "Opens an editor for a new view profile."),
81  i18nc("@info:whatsthis",
82  "If you press the <interface>Create new...</interface> button, "
83  "an editor is opened where you can create and edit a new view profile. "
84  "The values will be based on the ones of the view profile you selected "
85  "in the list.")),
86  page );
87  connect( createButton, SIGNAL(clicked(bool)), SLOT(onCreateNewButtonClicked()) );
88  buttonLayout->addWidget( createButton );
89  mEditButton =
90  new KPushButton(
91  KGuiItem(i18nc("@action:button",
92  "&Edit..."),
93  QLatin1String("document-edit"),
94  i18nc("@info:tooltip",
95  "Opens an editor for the view profile."),
96  i18nc("@info:whatsthis",
97  "If you press the <interface>Edit...</interface> button, "
98  "an editor will be opened for the view profile you selected "
99  "in the list.")),
100  page );
101  connect( mEditButton, SIGNAL(clicked(bool)), SLOT(onEditButtonClicked()) );
102  buttonLayout->addWidget( mEditButton );
103  mSetDefaultButton =
104  new KPushButton(
105  KGuiItem(i18nc("@action:button",
106  "&Set as Default"),
107  QString(),
108  i18nc("@info:tooltip",
109  "Sets the selected view profile as default for all views."),
110  i18nc("@info:whatsthis",
111  "If you press the <interface>Set as Default</interface> button, "
112  "the view profile you selected in the list is set as default for all views.")),
113  page );
114  connect( mSetDefaultButton, SIGNAL(clicked(bool)), SLOT(onSetDefaultButtonClicked()) );
115  buttonLayout->addWidget( mSetDefaultButton );
116  mDeleteButton =
117  new KPushButton(
118  KGuiItem(i18nc("@action:button",
119  "&Delete"),
120  QLatin1String("list-remove"),
121  i18nc("@info:tooltip",
122  "Deletes the selected view profile."),
123  i18nc("@info:whatsthis",
124  "If you press the <interface>Delete</interface> button, "
125  "the view profile you selected in the list is deleted.")),
126  page );
127  connect( mDeleteButton, SIGNAL(clicked(bool)), SLOT(onDeleteButtonClicked()) );
128  buttonLayout->addWidget( mDeleteButton );
129  buttonLayout->addStretch();
130 
131  pageLayout->addWidget( mViewProfileTableView );
132  pageLayout->addLayout( buttonLayout );
133 
134  setButtons( Close );
135 
136  connect( mViewProfileManager, SIGNAL(viewProfilesLocked(QList<Kasten2::ByteArrayViewProfile::Id>)),
137  SLOT(onViewProfilesLocked(QList<Kasten2::ByteArrayViewProfile::Id>)) );
138  connect( mViewProfileManager, SIGNAL(viewProfilesLocked(QList<Kasten2::ByteArrayViewProfile::Id>)),
139  SLOT(onViewProfilesUnlocked(QList<Kasten2::ByteArrayViewProfile::Id>)) );
140  connect( mViewProfileManager, SIGNAL(defaultViewProfileChanged(Kasten2::ByteArrayViewProfile::Id)),
141  SLOT(onDefaultViewProfileChanged(Kasten2::ByteArrayViewProfile::Id)) );
142 
143  // select first by default
144  onModelReset();
145 }
146 
147 
148 void
149 ViewProfilesManageDialog::onViewProfileSelectionChanged()
150 {
151  const QItemSelectionModel* selectionModel = mViewProfileTableView->selectionModel();
152  const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
153  const bool hasSelection = ( ! selectedIndexes.isEmpty() );
154 
155  mCurrentViewProfileId = hasSelection ? mViewProfileTableModel->viewProfileId( selectedIndexes.at(0) ) : ByteArrayViewProfile::Id();
156 
157  const bool isEditable = hasSelection &&
158  ! mViewProfileManager->isViewProfileLocked( mCurrentViewProfileId );
159 
160  mEditButton->setEnabled( isEditable );
161  mDeleteButton->setEnabled( isEditable );
162 
163  mSetDefaultButton->setEnabled( isEditable &&
164  mCurrentViewProfileId != mViewProfileManager->defaultViewProfileId() );
165 }
166 
167 void
168 ViewProfilesManageDialog::onCreateNewButtonClicked()
169 {
170  ViewProfileEditDialog* dialog = new ViewProfileEditDialog( this );
171  {
172  const bool isBasedOnExisting = (! mCurrentViewProfileId.isEmpty());
173  ByteArrayViewProfile newByteArrayViewProfile = isBasedOnExisting ?
174  mViewProfileManager->viewProfile( mCurrentViewProfileId ) : ByteArrayViewProfile();
175 
176  if( isBasedOnExisting )
177  {
178  // reset id
179  newByteArrayViewProfile.setId( QString() );
180  // twist title
181  const QString modifiedTitle = i18n( "Modification of %1", newByteArrayViewProfile.viewProfileTitle() );
182  newByteArrayViewProfile.setViewProfileTitle( modifiedTitle );
183  }
184 
185  dialog->setViewProfile( newByteArrayViewProfile );
186  const QString dialogTitle = i18nc( "@window:title",
187  "New View Profile" );
188  dialog->setWindowTitle( dialogTitle );
189  }
190 
191  const int answer = dialog->exec();
192 
193  if( answer == KDialog::Accepted )
194  {
195  QList<ByteArrayViewProfile> viewProfiles;
196  viewProfiles << dialog->viewProfile();
197  mViewProfileManager->saveViewProfiles( viewProfiles );
198  }
199 
200  delete dialog;
201 
202  setButtonFocus( Close );
203 }
204 
205 void
206 ViewProfilesManageDialog::onEditButtonClicked()
207 {
208  if( mCurrentViewProfileId.isEmpty() )
209  return;
210 
211  ByteArrayViewProfileLock viewProfileLock =
212  mViewProfileManager->createLock( mCurrentViewProfileId );
213 
214  if( ! viewProfileLock.isLocked() )
215  return;
216 
217  const ByteArrayViewProfile viewProfile =
218  mViewProfileManager->viewProfile( mCurrentViewProfileId );
219  ViewProfileEditDialog* dialog = new ViewProfileEditDialog( this );
220  dialog->setViewProfile( viewProfile );
221  const QString dialogTitle = i18nc( "@window:title",
222  "\"%1\" View Profile", viewProfile.viewProfileTitle() );
223  dialog->setWindowTitle( dialogTitle );
224 
225  const int answer = dialog->exec();
226  if( answer == KDialog::Accepted )
227  {
228  QList<ByteArrayViewProfile> viewProfiles;
229  viewProfiles << dialog->viewProfile();
230  mViewProfileManager->saveViewProfiles( viewProfiles );
231  }
232 
233  delete dialog;
234 
235  setButtonFocus( Close );
236 }
237 
238 void
239 ViewProfilesManageDialog::onSetDefaultButtonClicked()
240 {
241  if( mCurrentViewProfileId.isEmpty() )
242  return;
243 
244  mViewProfileManager->setDefaultViewProfile( mCurrentViewProfileId );
245 
246  setButtonFocus( Close );
247 }
248 
249 void
250 ViewProfilesManageDialog::onDeleteButtonClicked()
251 {
252  if( mCurrentViewProfileId.isEmpty() )
253  return;
254 
255  // TODO: ask user if she really wants to delete
256  QList<ByteArrayViewProfile::Id> viewProfileIds;
257  viewProfileIds << mCurrentViewProfileId;
258  mViewProfileManager->removeViewProfiles( viewProfileIds );
259 
260  setButtonFocus( Close );
261 }
262 
263 void
264 ViewProfilesManageDialog::onModelReset()
265 {
266  int row = mViewProfileTableModel->row( mCurrentViewProfileId );
267 
268  // no longer exists? set current to first if there is one
269  if( (row < 0) && (0 < mViewProfileManager->viewProfilesCount()) )
270  row = 0;
271 
272  const bool isViewProfileSelected = ( 0 <= row );
273  if( isViewProfileSelected )
274  {
275  const QItemSelection selection = QItemSelection( mViewProfileTableModel->index(row,ViewProfileTableModel::CurrentColumnId),
276  mViewProfileTableModel->index(row,ViewProfileTableModel::NameColumnId) );
277 
278  mViewProfileTableView->selectionModel()->select( selection, QItemSelectionModel::Select );
279  }
280  else
281  mCurrentViewProfileId.clear();
282  // TODO: show a ghost profile with the built-in parameters if there is none
283 
284  mEditButton->setEnabled( isViewProfileSelected );
285  mSetDefaultButton->setEnabled( isViewProfileSelected );
286  mDeleteButton->setEnabled( isViewProfileSelected );
287 }
288 
289 void
290 ViewProfilesManageDialog::onViewProfilesLocked( const QList<ByteArrayViewProfile::Id>& viewProfileIds )
291 {
292  // find if any locked profile is the currently selected, then disable all buttons
293  if( viewProfileIds.contains(mCurrentViewProfileId) )
294  {
295  mEditButton->setEnabled( false );
296  mDeleteButton->setEnabled( false );
297  mSetDefaultButton->setEnabled( false );
298  }
299 }
300 
301 void
302 ViewProfilesManageDialog::onViewProfilesUnlocked( const QList<ByteArrayViewProfile::Id>& viewProfileIds )
303 {
304  // find if any locked profile is the currently selected, then enable all buttons
305  if( viewProfileIds.contains(mCurrentViewProfileId) )
306  {
307  mEditButton->setEnabled( true );
308  mDeleteButton->setEnabled( true );
309  if( mCurrentViewProfileId != mViewProfileManager->defaultViewProfileId() )
310  mSetDefaultButton->setEnabled( true );
311  }
312 }
313 
314 void
315 ViewProfilesManageDialog::onDefaultViewProfileChanged( const ByteArrayViewProfile::Id& viewProfileId )
316 {
317  mSetDefaultButton->setEnabled( (! mCurrentViewProfileId.isEmpty()) &&
318  (mCurrentViewProfileId != viewProfileId) );
319 }
320 
321 
322 ViewProfilesManageDialog::~ViewProfilesManageDialog()
323 {
324 }
325 
326 }
Kasten2::ViewProfilesManageDialog::onViewProfilesUnlocked
void onViewProfilesUnlocked(const QList< Kasten2::ByteArrayViewProfile::Id > &viewProfileIds)
Definition: viewprofilesmanagedialog.cpp:302
bytearrayviewprofilelock.h
Kasten2::ByteArrayViewProfileManager::viewProfilesCount
int viewProfilesCount() const
Definition: bytearrayviewprofilemanager.cpp:175
Kasten2::ByteArrayViewProfileManager::removeViewProfiles
void removeViewProfiles(const QList< ByteArrayViewProfile::Id > &viewProfileIds)
Definition: bytearrayviewprofilemanager.cpp:273
Kasten2::ByteArrayViewProfile::Id
QString Id
Definition: bytearrayviewprofile.h:42
viewprofiletablemodel.h
Kasten2::ViewProfileTableModel::row
int row(const ByteArrayViewProfile::Id &viewProfileId) const
Definition: viewprofiletablemodel.cpp:132
Kasten2::ViewProfilesManageDialog::onDefaultViewProfileChanged
void onDefaultViewProfileChanged(const Kasten2::ByteArrayViewProfile::Id &viewProfileId)
Definition: viewprofilesmanagedialog.cpp:315
Kasten2::ViewProfilesManageDialog::onModelReset
void onModelReset()
Definition: viewprofilesmanagedialog.cpp:264
QWidget
Kasten2::ViewProfileTableModel::NameColumnId
Definition: viewprofiletablemodel.h:47
Kasten2::ByteArrayViewProfile
Definition: bytearrayviewprofile.h:39
Kasten2::ViewProfilesManageDialog::onSetDefaultButtonClicked
void onSetDefaultButtonClicked()
Definition: viewprofilesmanagedialog.cpp:239
Kasten2::ByteArrayViewProfileManager::isViewProfileLocked
bool isViewProfileLocked(const ByteArrayViewProfile::Id &id) const
Definition: bytearrayviewprofilemanager.cpp:217
Kasten2::ViewProfilesManageDialog::onEditButtonClicked
void onEditButtonClicked()
Definition: viewprofilesmanagedialog.cpp:206
bytearrayviewprofilemanager.h
KDialog
Kasten2::ByteArrayViewProfileLock
Definition: bytearrayviewprofilelock.h:38
Kasten2::ByteArrayViewProfileManager::saveViewProfiles
void saveViewProfiles(QList< ByteArrayViewProfile > &viewProfiles)
Definition: bytearrayviewprofilemanager.cpp:236
Kasten2::ViewProfileEditDialog
Definition: viewprofileeditdialog.h:35
Kasten2::ViewProfilesManageDialog::~ViewProfilesManageDialog
virtual ~ViewProfilesManageDialog()
Definition: viewprofilesmanagedialog.cpp:322
Kasten2::ViewProfileEditDialog::viewProfile
ByteArrayViewProfile viewProfile() const
Definition: viewprofileeditdialog.cpp:44
Kasten2::ViewProfileTableModel::CurrentColumnId
Definition: viewprofiletablemodel.h:46
Kasten2::ViewProfileTableModel::viewProfileId
ByteArrayViewProfile::Id viewProfileId(const QModelIndex &index) const
Definition: viewprofiletablemodel.cpp:122
Kasten2::ByteArrayViewProfileManager::defaultViewProfileId
ByteArrayViewProfile::Id defaultViewProfileId() const
Definition: bytearrayviewprofilemanager.cpp:205
viewprofilesmanagedialog.h
Kasten2::ByteArrayViewProfileManager::setDefaultViewProfile
void setDefaultViewProfile(const ByteArrayViewProfile::Id &viewProfileId)
Definition: bytearrayviewprofilemanager.cpp:283
Kasten2::ByteArrayViewProfileManager::createLock
ByteArrayViewProfileLock createLock(const ByteArrayViewProfile::Id &viewProfileId)
Definition: bytearrayviewprofilemanager.cpp:293
Kasten2::ViewProfilesManageDialog::onCreateNewButtonClicked
void onCreateNewButtonClicked()
Definition: viewprofilesmanagedialog.cpp:168
Kasten2::ViewProfilesManageDialog::ViewProfilesManageDialog
ViewProfilesManageDialog(ByteArrayViewProfileManager *viewProfileManager, QWidget *parent=0)
Definition: viewprofilesmanagedialog.cpp:43
Kasten2::ViewProfilesManageDialog::onViewProfilesLocked
void onViewProfilesLocked(const QList< Kasten2::ByteArrayViewProfile::Id > &viewProfileIds)
Definition: viewprofilesmanagedialog.cpp:290
Kasten2::ViewProfilesManageDialog::onDeleteButtonClicked
void onDeleteButtonClicked()
Definition: viewprofilesmanagedialog.cpp:250
Kasten2::ViewProfileTableModel
Definition: viewprofiletablemodel.h:39
Kasten2::viewProfileIds
static QList< ByteArrayViewProfile::Id > viewProfileIds(const QList< ByteArrayViewProfile > &viewProfiles)
Definition: bytearrayviewprofilemanager.cpp:58
Kasten2::ByteArrayViewProfileManager
Definition: bytearrayviewprofilemanager.h:65
Kasten2::ViewProfilesManageDialog::onViewProfileSelectionChanged
void onViewProfileSelectionChanged()
Definition: viewprofilesmanagedialog.cpp:149
Kasten2::ByteArrayViewProfile::viewProfileTitle
QString viewProfileTitle() const
Definition: bytearrayviewprofile.cpp:109
viewprofileeditdialog.h
Kasten2::ViewProfileEditDialog::setViewProfile
void setViewProfile(const ByteArrayViewProfile &viewProfile)
Definition: viewprofileeditdialog.cpp:51
Kasten2::ByteArrayViewProfileLock::isLocked
bool isLocked() const
Definition: bytearrayviewprofilelock.cpp:86
QList
Definition: bookmarkable.h:29
Kasten2::ByteArrayViewProfile::setViewProfileTitle
void setViewProfileTitle(const QString &title)
Definition: bytearrayviewprofile.cpp:124
Kasten2::ByteArrayViewProfile::setId
void setId(const Id &id)
Definition: bytearrayviewprofile.cpp:123
Kasten2::ByteArrayViewProfileManager::viewProfile
ByteArrayViewProfile viewProfile(const ByteArrayViewProfile::Id &id) const
Definition: bytearrayviewprofilemanager.cpp:188
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