• 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
  • transfer-plugins
  • contentfetch
scriptconfigadaptor.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2008 Ningyu Shi <shiningyu@gmail.com>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 */
10 
11 #include "scriptconfigadaptor.h"
12 
13 #include <QFileInfo>
14 #include <QString>
15 
16 #include <KStandardDirs>
17 #include <KDebug>
18 
19 bool ScriptConfigAdaptor::setFile(const QString &filename,
20  const QString &path)
21 {
22  if (!m_config)
23  {
24  if (!path.isEmpty())
25  {
26  QFileInfo info(path);
27  if (info.isDir() && info.exists())
28  {
29  // check for the ending slash
30  if (path.endsWith('/'))
31  {
32  m_config = new KConfig(path + filename);
33  }
34  else
35  {
36  m_config = new KConfig(path + '/' + filename);
37  }
38  return true;
39  }
40  else
41  {
42  return false;
43  }
44  }
45  else
46  {
47  QString default_path;
48  // put the config file in default user directory
49  // like ~/.kde4/share/app/kget/content_scrips_setting/
50  default_path = KStandardDirs::locateLocal("appdata", "contentfetch_scripts_setting/");
51  m_config = new KConfig(default_path + filename);
52  return true;
53  }
54  }
55  return false;
56 }
57 
58 void ScriptConfigAdaptor::unsetFile()
59 {
60  delete m_config;
61  m_config = 0;
62 }
63 
64 QVariant ScriptConfigAdaptor::read(const QString& group,
65  const QString& key,
66  const QVariant& defaultvalue)
67 {
68  m_group = m_config->group(group);
69  QVariant value;
70  switch(defaultvalue.type())
71  {
72  case QVariant::Int:
73  value = m_group.readEntry(key, defaultvalue.toInt());
74  break;
75  case QVariant::Double:
76  value = m_group.readEntry(key, defaultvalue.toDouble());
77  break;
78  case QVariant::StringList:
79  value = m_group.readEntry(key, defaultvalue.toStringList());
80  break;
81  case QVariant::List:
82  value = m_group.readEntry(key, defaultvalue.toList());
83  break;
84  default:
85  value = m_group.readEntry(key, defaultvalue.toString());
86  break;
87  };
88  return value;
89 }
90 
91 void ScriptConfigAdaptor::write(const QString& group,
92  const QString& key,
93  const QVariant& value)
94 {
95  m_group = m_config->group(group);
96  switch(value.type())
97  {
98  case QVariant::Int:
99  m_group.writeEntry(key, value.toInt());
100  break;
101  case QVariant::Double:
102  m_group.writeEntry(key, value.toDouble());
103  break;
104  case QVariant::StringList:
105  m_group.writeEntry(key, value.toStringList());
106  break;
107  case QVariant::List:
108  m_group.writeEntry(key, value.toList());
109  break;
110  default:
111  m_group.writeEntry(key, value.toString());
112  break;
113  };
114 }
115 
116 void ScriptConfigAdaptor::save()
117 {
118  m_config->sync();
119 }
120 
121 void ScriptConfigAdaptor::reset()
122 {
123  m_config->markAsClean();
124  m_config->reparseConfiguration();
125 }
ScriptConfigAdaptor::save
void save()
Definition: scriptconfigadaptor.cpp:116
ScriptConfigAdaptor::write
void write(const QString &group, const QString &key, const QVariant &value)
Definition: scriptconfigadaptor.cpp:91
ScriptConfigAdaptor::unsetFile
void unsetFile()
Definition: scriptconfigadaptor.cpp:58
ScriptConfigAdaptor::reset
void reset()
Discard current setting, reread from disk file.
Definition: scriptconfigadaptor.cpp:121
ScriptConfigAdaptor::read
QVariant read(const QString &group, const QString &key, const QVariant &defaultvalue=QVariant())
Definition: scriptconfigadaptor.cpp:64
ScriptConfigAdaptor::setFile
bool setFile(const QString &filename, const QString &path=QString())
Definition: scriptconfigadaptor.cpp:19
scriptconfigadaptor.h
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