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

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
  • config
  • appearance
contactlistlayoutwidget.cpp
Go to the documentation of this file.
1 /*
2  ContactList Layout Widget
3 
4  Copyright (c) 2009 by Roman Jarosz <kedgedev@gmail.com>
5 
6  Kopete (c) 2009 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include "contactlistlayoutwidget.h"
19 
20 #include <QInputDialog>
21 
22 #include <KMessageBox>
23 
24 #include "contactlistlayoutmanager.h"
25 
26 using namespace ContactList;
27 
28 ContactListLayoutWidget::ContactListLayoutWidget( QWidget *parent )
29 : QWidget( parent ), mChanged( false ), mLoading( false )
30 {
31  setupUi( this );
32 
33  QList<ContactListTokenConfig> tokens = LayoutManager::instance()->tokens();
34  for ( int i = 0; i < tokens.size(); i++)
35  {
36  ContactListTokenConfig clToken = tokens.at( i );
37  tokenPool->addToken( new Token( clToken.mName, clToken.mIconName, i ) );
38  }
39 
40  connect( layoutEdit, SIGNAL(changed()), this, SLOT(emitChanged()) );
41  connect( previewButton, SIGNAL(clicked()), this, SLOT(preview()) );
42  connect( removeButton, SIGNAL(clicked()), this, SLOT(remove()) );
43  connect( layoutComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setLayout(QString)) );
44  connect( LayoutManager::instance(), SIGNAL(layoutListChanged()), this, SLOT(reloadLayoutList()) );
45 }
46 
47 void ContactListLayoutWidget::load()
48 {
49  layoutComboBox->clear();
50 
51  QStringList layoutNames = LayoutManager::instance()->layouts();
52  layoutComboBox->addItems( layoutNames );
53 
54  int index = layoutNames.indexOf( LayoutManager::instance()->activeLayoutName() );
55  if ( index != -1 )
56  layoutComboBox->setCurrentIndex( index );
57 
58  setLayout( layoutComboBox->currentText() );
59  mChanged = false;
60 }
61 
62 bool ContactListLayoutWidget::save()
63 {
64  QString layoutName = mCurrentLayoutName;
65  if ( !saveLayoutData( layoutName ) )
66  return false;
67 
68  LayoutManager::instance()->setActiveLayout( layoutName );
69  mChanged = false;
70  return true;
71 }
72 
73 void ContactListLayoutWidget::emitChanged()
74 {
75  if ( !mChanged && !mLoading )
76  {
77  mChanged = true;
78  emit changed();
79  }
80 }
81 
82 void ContactListLayoutWidget::setLayout( const QString &layoutName )
83 {
84  if ( mCurrentLayoutName == layoutName )
85  return;
86 
87  QString layoutNameTmp = mCurrentLayoutName;
88  if ( !layoutNameTmp.isEmpty() && !saveLayoutData( layoutNameTmp, true ) )
89  {
90  int index = layoutComboBox->findText( mCurrentLayoutName );
91  if ( index != -1 )
92  layoutComboBox->setCurrentIndex( index );
93 
94  return;
95  }
96 
97  mLoading = true;
98  mCurrentLayoutName = layoutName;
99  removeButton->setEnabled( !LayoutManager::instance()->isDefaultLayout( layoutName ) );
100  ContactListLayout layout = LayoutManager::instance()->layout( layoutName );
101  layoutEdit->readLayout( layout.layout() );
102  mLoading = false;
103  mChanged = false;
104 
105  // Just emit changed because emitChanged is used only for layout data change
106  // and not for change of current active layout
107  if ( LayoutManager::instance()->activeLayoutName() != mCurrentLayoutName )
108  emit changed();
109 }
110 
111 void ContactListLayoutWidget::reloadLayoutList()
112 {
113  disconnect( layoutComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setLayout(QString)) );
114 
115  QString layoutName = layoutComboBox->currentText();
116  layoutComboBox->clear();
117  layoutComboBox->addItems( LayoutManager::instance()->layouts() );
118  int index = layoutComboBox->findText( layoutName );
119  if ( index != -1 )
120  {
121  layoutComboBox->setCurrentIndex( index );
122  }
123  else
124  {
125  mCurrentLayoutName.clear();
126  setLayout( layoutComboBox->currentText() );
127  LayoutManager::instance()->setActiveLayout( layoutComboBox->currentText() );
128  }
129 
130  connect( layoutComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setLayout(QString)) );
131 }
132 
133 void ContactListLayoutWidget::preview()
134 {
135  ContactListLayout layout;
136  layout.setLayout( layoutEdit->config() );
137  LayoutManager::instance()->setPreviewLayout( layout );
138 }
139 
140 void ContactListLayoutWidget::remove()
141 {
142  if ( !LayoutManager::instance()->isDefaultLayout( mCurrentLayoutName ) )
143  LayoutManager::instance()->deleteLayout( mCurrentLayoutName );
144 }
145 
146 bool ContactListLayoutWidget::saveLayoutData( QString& layoutName, bool showPrompt )
147 {
148  if ( mChanged )
149  {
150  if ( showPrompt )
151  {
152  int ret = KMessageBox::warningYesNoCancel( this, i18n( "Unsaved data?" ), i18n( "Layout" ), KStandardGuiItem::save(),
153  KStandardGuiItem::discard(), KStandardGuiItem::cancel(),
154  "askRemovingContactOrGroup", KMessageBox::Notify | KMessageBox::Dangerous );
155  if ( ret == KMessageBox::Cancel )
156  return false;
157  else if ( ret == KMessageBox::No )
158  return true;
159  }
160 
161  while ( ContactList::LayoutManager::instance()->isDefaultLayout( layoutName ) ) {
162  bool ok = false;
163  QString newLayoutName = QInputDialog::getText( this, i18n( "Reserved Layout Name" ),
164  i18n( "The layout '%1' is one of the default layouts and cannot be overwritten. Please select a different name.", layoutName ), QLineEdit::Normal, layoutName, &ok );
165  if ( !ok )
166  return false;
167  else if ( !newLayoutName.isEmpty() )
168  layoutName = newLayoutName;
169  }
170 
171  ContactListLayout layout;
172  layout.setLayout( layoutEdit->config() );
173  return LayoutManager::instance()->addUserLayout( layoutName, layout );
174  }
175  return true;
176 }
177 
178 #include "contactlistlayoutwidget.moc"
contactlistlayoutmanager.h
QWidget
ContactListLayoutWidget::ContactListLayoutWidget
ContactListLayoutWidget(QWidget *parent=0)
Definition: contactlistlayoutwidget.cpp:28
ContactList::ContactListLayout
Definition: contactlistlayoutitemconfig.h:92
ContactList::LayoutManager::instance
static LayoutManager * instance()
Definition: contactlistlayoutmanager.cpp:47
ContactList::ContactListTokenConfig::mName
QString mName
Definition: contactlistlayoutmanager.h:49
ContactList::ContactListTokenConfig
Definition: contactlistlayoutmanager.h:37
ContactList::ContactListLayout::setLayout
void setLayout(LayoutItemConfig layout)
Definition: contactlistlayoutitemconfig.cpp:102
ContactList::ContactListLayout::layout
LayoutItemConfig layout() const
Definition: contactlistlayoutitemconfig.cpp:97
ContactListLayoutWidget::save
bool save()
Definition: contactlistlayoutwidget.cpp:62
ContactList::ContactListTokenConfig::mIconName
QString mIconName
Definition: contactlistlayoutmanager.h:50
ContactListLayoutWidget::changed
void changed()
Token
Definition: Token.h:38
ContactListLayoutWidget::load
void load()
Definition: contactlistlayoutwidget.cpp:47
contactlistlayoutwidget.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

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

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