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

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • ui
  • metalinkcreator
localemodels.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
19 
20 #include "localemodels.h"
21 
22 #include <KGlobal>
23 #include <KLocale>
24 #include <KStandardDirs>
25 
26 CountryModel::CountryModel(QObject *parent)
27  : QAbstractListModel(parent)
28 {
29 }
30 
31 QVariant CountryModel::data(const QModelIndex &index, int role) const
32 {
33  if (!index.isValid())
34  {
35  return QVariant();
36  }
37 
38  if (role == Qt::DisplayRole)
39  {
40  return m_countryNames.value(index.row());
41  }
42  else if (role == Qt::DecorationRole)
43  {
44  return m_countryIcons.value(index.row());
45  }
46  else if (role == Qt::UserRole)
47  {
48  return m_countryCodes.value(index.row());
49  }
50 
51  return QVariant();
52 }
53 
54 int CountryModel::rowCount(const QModelIndex &parent) const
55 {
56  if (parent.isValid())
57  {
58  return 0;
59  }
60 
61  return m_countryCodes.count();
62 }
63 
64 void CountryModel::setupModelData(const QStringList &countryCodes)
65 {
66  foreach (const QString &countryCode, countryCodes)
67  {
68  const QString countryName = KGlobal::locale()->countryCodeToName(countryCode);
69  if (!countryName.isEmpty())
70  {
71  m_countryCodes.append(countryCode);
72  m_countryNames.append(countryName);
73 
74  QString path = KStandardDirs::locate("locale", QString::fromLatin1("l10n/%1/flag.png").arg(countryCode));
75  if (path.isEmpty())
76  {
77  m_countryIcons.append(KIcon());
78  }
79  else
80  {
81  m_countryIcons.append(KIcon(path));
82  }
83  }
84  }
85  reset();
86 }
87 
88 LanguageModel::LanguageModel(QObject *parent)
89 : QAbstractListModel(parent)
90 {
91 }
92 
93 QVariant LanguageModel::data(const QModelIndex &index, int role) const
94 {
95  if (!index.isValid())
96  {
97  return QVariant();
98  }
99 
100  if (role == Qt::DisplayRole)
101  {
102  return m_languageNames.value(index.row());
103  }
104  else if (role == Qt::UserRole)
105  {
106  return m_languageCodes.value(index.row());
107  }
108 
109  return QVariant();
110 }
111 
112 int LanguageModel::rowCount(const QModelIndex &parent) const
113 {
114  if (parent.isValid())
115  {
116  return 0;
117  }
118 
119  return m_languageCodes.count();
120 }
121 
122 void LanguageModel::setupModelData(const QStringList &languageCodes)
123 {
124  foreach (const QString &languageCode, languageCodes)
125  {
126  //no KDE-custom language-codes
127  if (languageCode.contains('@'))
128  {
129  continue;
130  }
131 
132  QString languageName = KGlobal::locale()->languageCodeToName(languageCode);
133  if (!languageName.isEmpty())
134  {
135  m_languageCodes.append(languageCode);
136  m_languageNames.append(languageName);
137  }
138  }
139  reset();
140 }
141 
142 #include "localemodels.moc"
localemodels.h
CountryModel::setupModelData
void setupModelData(const QStringList &countryCodes)
Definition: localemodels.cpp:64
LanguageModel::LanguageModel
LanguageModel(QObject *parent=0)
Definition: localemodels.cpp:88
QAbstractListModel
QObject
LanguageModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: localemodels.cpp:93
CountryModel::CountryModel
CountryModel(QObject *parent=0)
Definition: localemodels.cpp:26
LanguageModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: localemodels.cpp:112
LanguageModel::setupModelData
void setupModelData(const QStringList &languageCodes)
Definition: localemodels.cpp:122
CountryModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: localemodels.cpp:54
CountryModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: localemodels.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • 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