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

knotes

  • sources
  • kde-4.14
  • kdepim
  • knotes
  • print
knoteprintselectthemecombobox.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "knoteprintselectthemecombobox.h"
19 #include "knotesglobalconfig.h"
20 
21 #include <KStandardDirs>
22 #include <KConfigGroup>
23 #include <KConfig>
24 
25 #include <QDirIterator>
26 
27 KNotePrintSelectThemeComboBox::KNotePrintSelectThemeComboBox(QWidget *parent)
28  : QComboBox(parent)
29 {
30  loadThemes();
31 }
32 
33 KNotePrintSelectThemeComboBox::~KNotePrintSelectThemeComboBox()
34 {
35 
36 }
37 
38 void KNotePrintSelectThemeComboBox::loadThemes()
39 {
40  clear();
41  const QString defaultTheme = KNotesGlobalConfig::self()->theme();
42 
43  const QString relativePath = QLatin1String("knotes/print/themes/");
44  QStringList themesDirectories = KGlobal::dirs()->findDirs("data", relativePath);
45  if (themesDirectories.count() < 2) {
46  //Make sure to add local directory
47  const QString localDirectory = KStandardDirs::locateLocal("data", relativePath);
48  if (!themesDirectories.contains(localDirectory)) {
49  themesDirectories.append(localDirectory);
50  }
51  }
52 
53  Q_FOREACH (const QString &directory, themesDirectories) {
54  QDirIterator dirIt( directory, QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot );
55  QStringList alreadyLoadedThemeName;
56  while ( dirIt.hasNext() ) {
57  dirIt.next();
58  const QString themeInfoFile = dirIt.filePath() + QDir::separator() + QLatin1String("theme.desktop");
59  KConfig config( themeInfoFile );
60  KConfigGroup group( &config, QLatin1String( "Desktop Entry" ) );
61  QString name = group.readEntry( "Name", QString() );
62  if (name.isEmpty()) {
63  continue;
64  }
65  if (alreadyLoadedThemeName.contains(name)) {
66  int i = 2;
67  const QString originalName(name);
68  while (alreadyLoadedThemeName.contains(name)) {
69  name = originalName + QString::fromLatin1(" (%1)").arg(i);
70  ++i;
71  }
72  }
73  const QString printThemePath(dirIt.filePath() + QDir::separator());
74  if (!printThemePath.isEmpty()) {
75  alreadyLoadedThemeName << name;
76  addItem(name, printThemePath);
77  }
78  }
79  }
80  model()->sort(0);
81  const int index = findData(defaultTheme);
82  setCurrentIndex(index == -1 ? 0 : index);
83 }
84 
85 QString KNotePrintSelectThemeComboBox::selectedTheme() const
86 {
87  return itemData(currentIndex()).toString();
88 }
89 
90 void KNotePrintSelectThemeComboBox::selectDefaultTheme()
91 {
92  const bool bUseDefaults = KNotesGlobalConfig::self()->useDefaults( true );
93  const QString defaultTheme = KNotesGlobalConfig::self()->theme();
94  const int index = findData(defaultTheme);
95  setCurrentIndex(index == -1 ? 0 : index);
96  KNotesGlobalConfig::self()->useDefaults( bUseDefaults );
97 }
98 
QDirIterator::next
QString next()
QWidget
KNotePrintSelectThemeComboBox::selectedTheme
QString selectedTheme() const
Definition: knoteprintselectthemecombobox.cpp:85
QComboBox::model
QAbstractItemModel * model() const
QComboBox::clear
void clear()
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QDir::separator
QChar separator()
QAbstractItemModel::sort
virtual void sort(int column, Qt::SortOrder order)
QComboBox::addItem
void addItem(const QString &text, const QVariant &userData)
QObject::name
const char * name() const
QList::count
int count(const T &value) const
KNotePrintSelectThemeComboBox::loadThemes
void loadThemes()
Definition: knoteprintselectthemecombobox.cpp:38
QList::append
void append(const T &value)
KNotePrintSelectThemeComboBox::KNotePrintSelectThemeComboBox
KNotePrintSelectThemeComboBox(QWidget *parent=0)
Definition: knoteprintselectthemecombobox.cpp:27
knoteprintselectthemecombobox.h
QString::isEmpty
bool isEmpty() const
KNotePrintSelectThemeComboBox::selectDefaultTheme
void selectDefaultTheme()
Definition: knoteprintselectthemecombobox.cpp:90
QString
QStringList
QComboBox::itemData
QVariant itemData(int index, int role) const
QDirIterator
QComboBox::findData
int findData(const QVariant &data, int role, QFlags< Qt::MatchFlag > flags) const
QLatin1String
KNotePrintSelectThemeComboBox::~KNotePrintSelectThemeComboBox
~KNotePrintSelectThemeComboBox()
Definition: knoteprintselectthemecombobox.cpp:33
QComboBox::setCurrentIndex
void setCurrentIndex(int index)
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QDirIterator::hasNext
bool hasNext() const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
QDirIterator::filePath
QString filePath() const
QComboBox
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

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