summaryrefslogtreecommitdiff
authorkergoth <kergoth>2003-01-28 03:23:14 (UTC)
committer kergoth <kergoth>2003-01-28 03:23:14 (UTC)
commitde1321a53998bc1d078f9492395c2a26392875ed (patch) (unidiff)
treeb36d59612da5bbafeaddd28cb88a222b699d2645
parent728a7a4966c342be32c80c045cbae500160fc17b (diff)
downloadopie-de1321a53998bc1d078f9492395c2a26392875ed.zip
opie-de1321a53998bc1d078f9492395c2a26392875ed.tar.gz
opie-de1321a53998bc1d078f9492395c2a26392875ed.tar.bz2
Added a Config derivative.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.cpp23
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.h4
-rw-r--r--noncore/apps/tinykate/libkate/document/katehighlight.cpp36
-rw-r--r--noncore/apps/tinykate/libkate/document/katehighlight.h8
-rw-r--r--noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp12
-rw-r--r--noncore/apps/tinykate/libkate/interfaces/document.h6
-rw-r--r--noncore/apps/tinykate/libkate/interfaces/view.h6
-rw-r--r--noncore/apps/tinykate/libkate/kateconfig.cpp634
-rw-r--r--noncore/apps/tinykate/libkate/kateconfig.h117
-rw-r--r--noncore/apps/tinykate/libkate/libkate.pro9
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kconfig.cpp181
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kconfig.h51
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kglobal.cpp6
-rw-r--r--noncore/apps/tinykate/libkate/microkde/kglobal.h6
-rw-r--r--noncore/apps/tinykate/libkate/view/kateview.cpp18
-rw-r--r--noncore/apps/tinykate/libkate/view/kateview.h9
-rw-r--r--noncore/apps/tinykate/tinykate.cpp10
-rw-r--r--noncore/apps/tinykate/tinykate.h3
-rw-r--r--noncore/apps/tinykate/tinykate.pro4
19 files changed, 835 insertions, 308 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp
index df1de8d..6807544 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.cpp
+++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp
@@ -280,6 +280,7 @@ void KateDocument::doPreHighlight()
280KateDocument::~KateDocument() 280KateDocument::~KateDocument()
281{ 281{
282 m_highlight->release(); 282 m_highlight->release();
283 writeConfig();
283 284
284 if ( !m_bSingleViewMode ) 285 if ( !m_bSingleViewMode )
285 { 286 {
@@ -596,7 +597,7 @@ bool KateDocument::isModified() const {
596 597
597void KateDocument::readConfig() 598void KateDocument::readConfig()
598{ 599{
599 KConfig *config = KGlobal::config(); 600 KateConfig *config = KGlobal::config();
600 config->setGroup("Kate Document"); 601 config->setGroup("Kate Document");
601 602
602 myWordWrap = config->readBoolEntry("Word Wrap On", false); 603 myWordWrap = config->readBoolEntry("Word Wrap On", false);
@@ -608,20 +609,19 @@ void KateDocument::readConfig()
608 setUndoSteps(config->readNumEntry("UndoSteps", 50)); 609 setUndoSteps(config->readNumEntry("UndoSteps", 50));
609 m_singleSelection = config->readBoolEntry("SingleSelection", false); 610 m_singleSelection = config->readBoolEntry("SingleSelection", false);
610 myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); 611 myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name()));
611 setFont (config->readFontEntry("Font", &myFont)); 612 setFont (config->readFontEntry("Font", myFont));
612 613
613 colors[0] = config->readColorEntry("Color Background", &colors[0]); 614 colors[0] = config->readColorEntry("Color Background", colors[0]);
614 colors[1] = config->readColorEntry("Color Selected", &colors[1]); 615 colors[1] = config->readColorEntry("Color Selected", colors[1]);
615 616
616 config->sync(); 617// config->sync();
617} 618}
618 619
619void KateDocument::writeConfig() 620void KateDocument::writeConfig()
620{ 621{
621 KConfig *config = KGlobal::config(); 622 KateConfig *config = KGlobal::config();
622 config->setGroup("Kate Document"); 623 config->setGroup("Kate Document");
623#if 0 624 config->writeEntry("Word Wrap On", myWordWrap);
624 cofig->writeEntry("Word Wrap On", myWordWrap);
625 config->writeEntry("Word Wrap At", myWordWrapAt); 625 config->writeEntry("Word Wrap At", myWordWrapAt);
626 config->writeEntry("TabWidth", tabChars); 626 config->writeEntry("TabWidth", tabChars);
627 config->writeEntry("UndoSteps", undoSteps); 627 config->writeEntry("UndoSteps", undoSteps);
@@ -630,11 +630,10 @@ void KateDocument::writeConfig()
630 config->writeEntry("Font", myFont); 630 config->writeEntry("Font", myFont);
631 config->writeEntry("Color Background", colors[0]); 631 config->writeEntry("Color Background", colors[0]);
632 config->writeEntry("Color Selected", colors[1]); 632 config->writeEntry("Color Selected", colors[1]);
633#endif 633// config->sync();
634 config->sync();
635} 634}
636 635
637void KateDocument::readSessionConfig(KConfig *config) 636void KateDocument::readSessionConfig(KateConfig *config)
638{ 637{
639 m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) 638 m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon)
640 setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); 639 setHighlight(hlManager->nameFind(config->readEntry("Highlight")));
@@ -648,7 +647,7 @@ void KateDocument::readSessionConfig(KConfig *config)
648 } 647 }
649} 648}
650 649
651void KateDocument::writeSessionConfig(KConfig *config) 650void KateDocument::writeSessionConfig(KateConfig *config)
652{ 651{
653#if 0 652#if 0
654 config->writeEntry("URL", m_url); // ### encoding?? (Simon) 653 config->writeEntry("URL", m_url); // ### encoding?? (Simon)
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h
index 356541f..9d8ec6a 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.h
+++ b/noncore/apps/tinykate/libkate/document/katedocument.h
@@ -229,8 +229,8 @@ class KateDocument: public Kate::Document
229 229
230 void readConfig(); 230 void readConfig();
231 void writeConfig(); 231 void writeConfig();
232 void readSessionConfig(KConfig *); 232 void readSessionConfig(KateConfig *);
233 void writeSessionConfig(KConfig *); 233 void writeSessionConfig(KateConfig *);
234 234
235 bool hasBrowserExtension() const { return m_bBrowserView; } 235 bool hasBrowserExtension() const { return m_bBrowserView; }
236 236
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.cpp b/noncore/apps/tinykate/libkate/document/katehighlight.cpp
index 797968b..0d2c283 100644
--- a/noncore/apps/tinykate/libkate/document/katehighlight.cpp
+++ b/noncore/apps/tinykate/libkate/document/katehighlight.cpp
@@ -649,17 +649,17 @@ int Highlight::doHighlight(int ctxNum, TextLine *textLine)
649 return context->ctx; 649 return context->ctx;
650} 650}
651 651
652KConfig *Highlight::getKConfig() { 652KateConfig *Highlight::getKateConfig() {
653 KConfig *config; 653 KateConfig *config;
654 config=KGlobal::config(); 654 config=KGlobal::config();
655 config->setGroup(iName + QString(" Highlight")); 655 config->setGroup(iName + QString(" Highlight"));
656 return config; 656 return config;
657} 657}
658 658
659QString Highlight::getWildcards() { 659QString Highlight::getWildcards() {
660 KConfig *config; 660 KateConfig *config;
661 661
662 config = getKConfig(); 662 config = getKateConfig();
663 663
664 //if wildcards not yet in config, then use iWildCards as default 664 //if wildcards not yet in config, then use iWildCards as default
665 return config->readEntry("Wildcards", iWildcards); 665 return config->readEntry("Wildcards", iWildcards);
@@ -667,19 +667,19 @@ QString Highlight::getWildcards() {
667 667
668 668
669QString Highlight::getMimetypes() { 669QString Highlight::getMimetypes() {
670 KConfig *config; 670 KateConfig *config;
671 671
672 config = getKConfig(); 672 config = getKateConfig();
673 673
674 return config->readEntry("Mimetypes", iMimetypes); 674 return config->readEntry("Mimetypes", iMimetypes);
675} 675}
676 676
677 677
678HlData *Highlight::getData() { 678HlData *Highlight::getData() {
679 KConfig *config; 679 KateConfig *config;
680 HlData *hlData; 680 HlData *hlData;
681 681
682 config = getKConfig(); 682 config = getKateConfig();
683 683
684// iWildcards = config->readEntry("Wildcards"); 684// iWildcards = config->readEntry("Wildcards");
685// iMimetypes = config->readEntry("Mimetypes"); 685// iMimetypes = config->readEntry("Mimetypes");
@@ -693,9 +693,9 @@ HlData *Highlight::getData() {
693} 693}
694 694
695void Highlight::setData(HlData *hlData) { 695void Highlight::setData(HlData *hlData) {
696 KConfig *config; 696 KateConfig *config;
697 697
698 config = getKConfig(); 698 config = getKateConfig();
699 699
700// iWildcards = hlData->wildcards; 700// iWildcards = hlData->wildcards;
701// iMimetypes = hlData->mimetypes; 701// iMimetypes = hlData->mimetypes;
@@ -707,13 +707,13 @@ void Highlight::setData(HlData *hlData) {
707} 707}
708 708
709void Highlight::getItemDataList(ItemDataList &list) { 709void Highlight::getItemDataList(ItemDataList &list) {
710 KConfig *config; 710 KateConfig *config;
711 711
712 config = getKConfig(); 712 config = getKateConfig();
713 getItemDataList(list, config); 713 getItemDataList(list, config);
714} 714}
715 715
716void Highlight::getItemDataList(ItemDataList &list, KConfig *config) { 716void Highlight::getItemDataList(ItemDataList &list, KateConfig *config) {
717 ItemData *p; 717 ItemData *p;
718 QString s; 718 QString s;
719 QRgb col, selCol; 719 QRgb col, selCol;
@@ -739,7 +739,7 @@ void Highlight::getItemDataList(ItemDataList &list, KConfig *config) {
739 739
740 * input: ItemDataList &list :reference to the list, whose 740 * input: ItemDataList &list :reference to the list, whose
741 * items should be saved 741 * items should be saved
742 * KConfig *config :Pointer KDE configuration 742 * KateConfig *config :Pointer KDE configuration
743 * class, which should be used 743 * class, which should be used
744 * as storage 744 * as storage
745 ************* 745 *************
@@ -748,7 +748,7 @@ void Highlight::getItemDataList(ItemDataList &list, KConfig *config) {
748 * return value: none 748 * return value: none
749*******************************************************************************************/ 749*******************************************************************************************/
750 750
751void Highlight::setItemDataList(ItemDataList &list, KConfig *config) { 751void Highlight::setItemDataList(ItemDataList &list, KateConfig *config) {
752 ItemData *p; 752 ItemData *p;
753 QString s; 753 QString s;
754 754
@@ -1266,7 +1266,7 @@ Highlight *HlManager::getHl(int n) {
1266} 1266}
1267 1267
1268int HlManager::defaultHl() { 1268int HlManager::defaultHl() {
1269 KConfig *config; 1269 KateConfig *config;
1270 config = KGlobal::config(); 1270 config = KGlobal::config();
1271 config->setGroup("General Options"); 1271 config->setGroup("General Options");
1272 1272
@@ -1374,7 +1374,7 @@ QString HlManager::defaultStyleName(int n)
1374} 1374}
1375 1375
1376void HlManager::getDefaults(ItemStyleList &list) { 1376void HlManager::getDefaults(ItemStyleList &list) {
1377 KConfig *config; 1377 KateConfig *config;
1378 int z; 1378 int z;
1379 ItemStyle *i; 1379 ItemStyle *i;
1380 QString s; 1380 QString s;
@@ -1410,7 +1410,7 @@ void HlManager::getDefaults(ItemStyleList &list) {
1410} 1410}
1411 1411
1412void HlManager::setDefaults(ItemStyleList &list) { 1412void HlManager::setDefaults(ItemStyleList &list) {
1413 KConfig *config; 1413 KateConfig *config;
1414 int z; 1414 int z;
1415 ItemStyle *i; 1415 ItemStyle *i;
1416 char s[64]; 1416 char s[64];
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.h b/noncore/apps/tinykate/libkate/document/katehighlight.h
index 1baddcc..fddf585 100644
--- a/noncore/apps/tinykate/libkate/document/katehighlight.h
+++ b/noncore/apps/tinykate/libkate/document/katehighlight.h
@@ -236,7 +236,7 @@ class HlData {
236typedef QList<HlData> HlDataList; 236typedef QList<HlData> HlDataList;
237 237
238class HlManager; 238class HlManager;
239class KConfig; 239class KateConfig;
240 240
241//context 241//context
242class HlContext { 242class HlContext {
@@ -258,14 +258,14 @@ class Highlight
258 258
259 int doHighlight(int ctxNum, TextLine *); 259 int doHighlight(int ctxNum, TextLine *);
260 260
261 KConfig *getKConfig(); 261 KateConfig *getKateConfig();
262 QString getWildcards(); 262 QString getWildcards();
263 QString getMimetypes(); 263 QString getMimetypes();
264 HlData *getData(); 264 HlData *getData();
265 void setData(HlData *); 265 void setData(HlData *);
266 void getItemDataList(ItemDataList &); 266 void getItemDataList(ItemDataList &);
267 void getItemDataList(ItemDataList &, KConfig *); 267 void getItemDataList(ItemDataList &, KateConfig *);
268 void setItemDataList(ItemDataList &, KConfig *); 268 void setItemDataList(ItemDataList &, KateConfig *);
269 QString name() {return iName;} 269 QString name() {return iName;}
270 QString section() {return iSection;} 270 QString section() {return iSection;}
271 void use(); 271 void use();
diff --git a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp
index e45daa4..844f27d 100644
--- a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp
+++ b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp
@@ -16,13 +16,13 @@
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include "katesyntaxdocument.h" 18#include "katesyntaxdocument.h"
19#include <kateconfig.h>
19#include <qfile.h> 20#include <qfile.h>
20#include <kdebug.h> 21#include <kdebug.h>
21#include <kstddirs.h> 22#include <kstddirs.h>
22#include <klocale.h> 23#include <klocale.h>
23#include <kmessagebox.h> 24#include <kmessagebox.h>
24#include <qstringlist.h> 25#include <qstringlist.h>
25#include <kconfig.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qdir.h> 28#include <qdir.h>
@@ -51,7 +51,7 @@ void SyntaxDocument::setupModeList(bool force)
51 51
52 if (myModeList.count() > 0) return; 52 if (myModeList.count() > 0) return;
53 53
54 KConfig *config=KGlobal::config(); 54 KateConfig *config=KGlobal::config();
55 KStandardDirs *dirs = KGlobal::dirs(); 55 KStandardDirs *dirs = KGlobal::dirs();
56 56
57// QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true); 57// QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true);
@@ -63,7 +63,6 @@ void SyntaxDocument::setupModeList(bool force)
63 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 63 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
64 { 64 {
65 QString Group="Highlighting_Cache"+path+*it; 65 QString Group="Highlighting_Cache"+path+*it;
66
67 if ((config->hasGroup(Group)) && (!force)) 66 if ((config->hasGroup(Group)) && (!force))
68 { 67 {
69 config->setGroup(Group); 68 config->setGroup(Group);
@@ -96,21 +95,16 @@ void SyntaxDocument::setupModeList(bool force)
96 mli->section=i18n("Other"); 95 mli->section=i18n("Other");
97 96
98 mli->identifier = path+(*it); 97 mli->identifier = path+(*it);
99#warning fixme
100/*
101 config->setGroup(Group); 98 config->setGroup(Group);
102 config->writeEntry("name",mli->name); 99 config->writeEntry("name",mli->name);
103 config->writeEntry("section",mli->section); 100 config->writeEntry("section",mli->section);
104 config->writeEntry("mimetype",mli->mimetype); 101 config->writeEntry("mimetype",mli->mimetype);
105 config->writeEntry("extension",mli->extension); 102 config->writeEntry("extension",mli->extension);
106*/
107 myModeList.append(mli); 103 myModeList.append(mli);
108 } 104 }
109 } 105 }
110 }
111 } 106 }
112// } 107 }
113
114// config->sync(); 108// config->sync();
115} 109}
116 110
diff --git a/noncore/apps/tinykate/libkate/interfaces/document.h b/noncore/apps/tinykate/libkate/interfaces/document.h
index cbfd1b3..af885f1 100644
--- a/noncore/apps/tinykate/libkate/interfaces/document.h
+++ b/noncore/apps/tinykate/libkate/interfaces/document.h
@@ -30,7 +30,7 @@
30 30
31#include <ktexteditor.h> 31#include <ktexteditor.h>
32 32
33class KConfig; 33class KateConfig;
34 34
35namespace Kate 35namespace Kate
36{ 36{
@@ -63,10 +63,10 @@ class Document : public KTextEditor::Document
63 63
64 /** Read document session config. 64 /** Read document session config.
65 */ 65 */
66 virtual void readSessionConfig (KConfig *) { ; }; 66 virtual void readSessionConfig (KateConfig *) { ; };
67 /** Save document session config. 67 /** Save document session config.
68 */ 68 */
69 virtual void writeSessionConfig (KConfig *) { ; }; 69 virtual void writeSessionConfig (KateConfig *) { ; };
70 70
71 /** Returns the document ID. 71 /** Returns the document ID.
72 */ 72 */
diff --git a/noncore/apps/tinykate/libkate/interfaces/view.h b/noncore/apps/tinykate/libkate/interfaces/view.h
index 5b24bb5..5846395 100644
--- a/noncore/apps/tinykate/libkate/interfaces/view.h
+++ b/noncore/apps/tinykate/libkate/interfaces/view.h
@@ -30,7 +30,7 @@
30 30
31#include <ktexteditor.h> 31#include <ktexteditor.h>
32 32
33class KConfig; 33class KateConfig;
34 34
35namespace Kate 35namespace Kate
36{ 36{
@@ -79,8 +79,8 @@ class View : public KTextEditor::View
79 virtual void writeConfig () { ; }; 79 virtual void writeConfig () { ; };
80 80
81 // read/save sessionconfig of the view 81 // read/save sessionconfig of the view
82 virtual void readSessionConfig (KConfig *) { ; }; 82 virtual void readSessionConfig (KateConfig *) { ; };
83 virtual void writeSessionConfig (KConfig *) { ; }; 83 virtual void writeSessionConfig (KateConfig *) { ; };
84 84
85 public slots: 85 public slots:
86 // some simply key commands 86 // some simply key commands
diff --git a/noncore/apps/tinykate/libkate/kateconfig.cpp b/noncore/apps/tinykate/libkate/kateconfig.cpp
new file mode 100644
index 0000000..06ac49f
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/kateconfig.cpp
@@ -0,0 +1,634 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qdir.h>
22#include <qfile.h>
23#include <qfileinfo.h>
24#include <qmessagebox.h>
25#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
26#include <qtextcodec.h>
27#endif
28#include <qtextstream.h>
29
30#include <sys/stat.h>
31#include <sys/types.h>
32#include <fcntl.h>
33#include <stdlib.h>
34#include <unistd.h>
35
36#define QTOPIA_INTERNAL_LANGLIST
37#include "kateconfig.h"
38#include <qpe/global.h>
39
40
41/*!
42 \internal
43*/
44QString KateConfig::configFilename(const QString& name, Domain d)
45{
46 switch (d) {
47 case File:
48 return name;
49 case User: {
50 QDir dir = (QString(getenv("HOME")) + "/Settings");
51 if ( !dir.exists() )
52 mkdir(dir.path().local8Bit(),0700);
53 return dir.path() + "/" + name + ".conf";
54 }
55 }
56 return name;
57}
58
59/*!
60 \class KateConfig config.h
61 \brief The KateConfig class provides for saving application cofniguration state.
62
63 You should keep a KateConfig in existence only while you do not want others
64 to be able to change the state. There is no locking currently, but there
65 may be in the future.
66*/
67
68/*!
69 \enum KateConfig::KateConfigGroup
70 \internal
71*/
72
73/*!
74 \enum KateConfig::Domain
75
76 \value File
77 \value User
78
79 See KateConfig for details.
80*/
81
82/*!
83 Constructs a config that will load or create a configuration with the
84 given \a name in the given \a domain.
85
86 You must call setGroup() before doing much else with the KateConfig.
87
88 In the default Domain, \e User,
89 the configuration is user-specific. \a name should not contain "/" in
90 this case, and in general should be the name of the C++ class that is
91 primarily responsible for maintaining the configuration.
92
93 In the File Domain, \a name is an absolute filename.
94*/
95KateConfig::KateConfig( const QString &name, Domain domain )
96 : filename( configFilename(name,domain) )
97{
98 qWarning("KateConfig constructor\n");
99 git = groups.end();
100 read();
101 QStringList l = Global::languageList();
102 lang = l[0];
103 glang = l[1];
104}
105
106
107// Sharp ROM compatibility
108KateConfig::KateConfig ( const QString &name, bool what )
109 : filename( configFilename(name,what ? User : File) )
110{
111 git = groups.end();
112 read();
113 QStringList l = Global::languageList();
114 lang = l[0];
115 glang = l[1];
116}
117
118/*!
119 Writes any changes to disk and destroys the in-memory object.
120*/
121KateConfig::~KateConfig()
122{
123 qWarning("KateConfig destructor\n");
124 if ( changed )
125 write();
126}
127
128/*!
129 Returns whether the current group has an entry called \a key.
130*/
131bool KateConfig::hasKey( const QString &key ) const
132{
133 if ( groups.end() == git )
134 return FALSE;
135 KateConfigGroup::ConstIterator it = ( *git ).find( key );
136 return it != ( *git ).end();
137}
138
139/*!
140 Sets the current group for subsequent reading and writing of
141 entries to \a gname. Grouping allows the application to partition the namespace.
142
143 This function must be called prior to any reading or writing
144 of entries.
145
146 The \a gname must not be empty.
147*/
148void KateConfig::setGroup( const QString &gname )
149{
150 QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname );
151 if ( it == groups.end() ) {
152 git = groups.insert( gname, KateConfigGroup() );
153 changed = TRUE;
154 return;
155 }
156 git = it;
157}
158
159/*!
160 Writes a (\a key, \a value) entry to the current group.
161
162 \sa readEntry()
163*/
164void KateConfig::writeEntry( const QString &key, const char* value )
165{
166 writeEntry(key,QString(value));
167}
168
169/*!
170 Writes a (\a key, \a value) entry to the current group.
171
172 \sa readEntry()
173*/
174void KateConfig::writeEntry( const QString &key, const QString &value )
175{
176 if ( git == groups.end() ) {
177 qWarning( "no group set" );
178 return;
179 }
180 if ( (*git)[key] != value ) {
181 ( *git ).insert( key, value );
182 changed = TRUE;
183 }
184}
185
186/*
187 Note that the degree of protection offered by the encryption here is
188 only sufficient to avoid the most casual observation of the configuration
189 files. People with access to the files can write down the contents and
190 decrypt it using this source code.
191
192 Conceivably, and at some burden to the user, this encryption could
193 be improved.
194*/
195static QString encipher(const QString& plain)
196{
197 // mainly, we make it long
198 QString cipher;
199 int mix=28730492;
200 for (int i=0; i<(int)plain.length(); i++) {
201 int u = plain[i].unicode();
202 int c = u ^ mix;
203 QString x = QString::number(c,36);
204 cipher.append(QChar('a'+x.length()));
205 cipher.append(x);
206 mix *= u;
207 }
208 return cipher;
209}
210
211static QString decipher(const QString& cipher)
212{
213 QString plain;
214 int mix=28730492;
215 for (int i=0; i<(int)cipher.length();) {
216 int l = cipher[i].unicode()-'a';
217 QString x = cipher.mid(i+1,l); i+=l+1;
218 int u = x.toInt(0,36) ^ mix;
219 plain.append(QChar(u));
220 mix *= u;
221 }
222 return plain;
223}
224
225/*!
226 Writes an encrypted (\a key, \a value) entry to the current group.
227
228 Note that the degree of protection offered by the encryption is
229 only sufficient to avoid the most casual observation of the configuration
230 files.
231
232 \sa readEntry()
233*/
234void KateConfig::writeEntryCrypt( const QString &key, const QString &value )
235{
236 if ( git == groups.end() ) {
237 qWarning( "no group set" );
238 return;
239 }
240 QString evalue = encipher(value);
241 if ( (*git)[key] != evalue ) {
242 ( *git ).insert( key, evalue );
243 changed = TRUE;
244 }
245}
246
247/*!
248 Writes a (\a key, \a num) entry to the current group.
249
250 \sa readNumEntry()
251*/
252void KateConfig::writeEntry( const QString &key, int num )
253{
254 QString s;
255 s.setNum( num );
256 writeEntry( key, s );
257}
258
259void KateConfig::writeEntry( const QString &key, unsigned int num )
260{
261 QString s;
262 s.setNum( num );
263 writeEntry( key, s );
264}
265
266#ifdef Q_HAS_BOOL_TYPE
267/*!
268 Writes a (\a key, \a b) entry to the current group. This is equivalent
269 to writing a 0 or 1 as an integer entry.
270
271 \sa readBoolEntry()
272*/
273void KateConfig::writeEntry( const QString &key, bool b )
274{
275 QString s;
276 s.setNum( ( int )b );
277 writeEntry( key, s );
278}
279#endif
280
281/*!
282 Writes a (\a key, \a lst) entry to the current group. The list
283 is separated by \a sep, so the strings must not contain that character.
284
285 \sa readListEntry()
286*/
287void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep )
288{
289 QString s;
290 QStringList::ConstIterator it = lst.begin();
291 for ( ; it != lst.end(); ++it )
292 s += *it + sep;
293 writeEntry( key, s );
294}
295
296void KateConfig::writeEntry( const QString &key, const QColor &val )
297{
298 QStringList l;
299 l.append( QString().setNum(val.red()) );
300 l.append( QString().setNum(val.green()) );
301 l.append( QString().setNum(val.blue()) );
302
303 writeEntry( key, l, QChar(',') );
304}
305
306void KateConfig::writeEntry( const QString &key, const QFont &val )
307{
308 QStringList l;
309 l.append( val.family() );
310 l.append( QString().setNum(val.pointSize()) );
311 l.append( QString().setNum(val.weight()) );
312 l.append( QString().setNum((int)val.italic()) );
313 l.append( QString().setNum((int)val.charSet()) );
314
315 writeEntry( key, l, QChar(',') );
316}
317
318/*!
319 Removes the \a key entry from the current group. Does nothing if
320 there is no such entry.
321*/
322
323void KateConfig::removeEntry( const QString &key )
324{
325 if ( git == groups.end() ) {
326 qWarning( "no group set" );
327 return;
328 }
329 ( *git ).remove( key );
330 changed = TRUE;
331}
332
333/*!
334 \fn bool KateConfig::operator == ( const KateConfig & other ) const
335
336 Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename.
337*/
338
339/*!
340 \fn bool KateConfig::operator != ( const KateConfig & other ) const
341
342 Tests for inequality with \a other. KateConfig objects are equal if they refer to the same filename.
343*/
344
345/*!
346 \fn QString KateConfig::readEntry( const QString &key, const QString &deflt ) const
347
348 Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry.
349*/
350
351/*!
352 \internal
353 For compatibility, non-const version.
354*/
355QString KateConfig::readEntry( const QString &key, const QString &deflt )
356{
357 QString res = readEntryDirect( key+"["+lang+"]" );
358 if ( !res.isNull() )
359 return res;
360 if ( !glang.isEmpty() ) {
361 res = readEntryDirect( key+"["+glang+"]" );
362 if ( !res.isNull() )
363 return res;
364 }
365 return readEntryDirect( key, deflt );
366}
367
368/*!
369 \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const
370
371 Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry.
372*/
373
374/*!
375 \internal
376 For compatibility, non-const version.
377*/
378QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt )
379{
380 QString res = readEntryDirect( key+"["+lang+"]" );
381 if ( res.isNull() && glang.isEmpty() )
382 res = readEntryDirect( key+"["+glang+"]" );
383 if ( res.isNull() )
384 res = readEntryDirect( key, QString::null );
385 if ( res.isNull() )
386 return deflt;
387 return decipher(res);
388}
389
390/*!
391 \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const
392 \internal
393*/
394
395/*!
396 \internal
397 For compatibility, non-const version.
398*/
399QString KateConfig::readEntryDirect( const QString &key, const QString &deflt )
400{
401 if ( git == groups.end() ) {
402 //qWarning( "no group set" );
403 return deflt;
404 }
405 KateConfigGroup::ConstIterator it = ( *git ).find( key );
406 if ( it != ( *git ).end() )
407 return *it;
408 else
409 return deflt;
410}
411
412/*!
413 \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const
414 Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry.
415*/
416
417/*!
418 \internal
419 For compatibility, non-const version.
420*/
421int KateConfig::readNumEntry( const QString &key, int deflt )
422{
423 QString s = readEntry( key );
424 if ( s.isEmpty() )
425 return deflt;
426 else
427 return s.toInt();
428}
429
430/*!
431 \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const
432 Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry.
433*/
434
435/*!
436 \internal
437 For compatibility, non-const version.
438*/
439bool KateConfig::readBoolEntry( const QString &key, bool deflt )
440{
441 QString s = readEntry( key );
442 if ( s.isEmpty() )
443 return deflt;
444 else
445 return (bool)s.toInt();
446}
447
448/*!
449 \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const
450 Reads a string list entry stored with \a key, and with \a sep as the separator.
451*/
452
453/*!
454 \internal
455 For compatibility, non-const version.
456*/
457QStringList KateConfig::readListEntry( const QString &key, const QChar &sep )
458{
459 QString s = readEntry( key );
460 if ( s.isEmpty() )
461 return QStringList();
462 else
463 return QStringList::split( sep, s );
464}
465
466QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const
467{
468 QStringList list = readListEntry(key, QChar(','));
469 if( list.count() != 3 )
470 return def;
471
472 return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt());
473}
474
475QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const
476{
477 QStringList list = readListEntry(key, QChar(','));
478 if( list.count() != 5 )
479 return def;
480
481 return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt());
482}
483
484QValueList<int> KateConfig::readIntListEntry( const QString &key ) const
485{
486 QString s = readEntry( key );
487 QValueList<int> il;
488 if ( s.isEmpty() )
489 return il;
490
491 QStringList l = QStringList::split( QChar(','), s );
492
493 QStringList::Iterator l_it;
494 for( l_it = l.begin(); l_it != l.end(); ++l_it )
495 il.append( (*l_it).toInt() );
496 return il;
497}
498
499/*!
500 Removes all entries from the current group.
501*/
502void KateConfig::clearGroup()
503{
504 if ( git == groups.end() ) {
505 qWarning( "no group set" );
506 return;
507 }
508 if ( !(*git).isEmpty() ) {
509 ( *git ).clear();
510 changed = TRUE;
511 }
512}
513
514/*!
515 \internal
516*/
517void KateConfig::write( const QString &fn )
518{
519 QString strNewFile;
520 if ( !fn.isEmpty() )
521 filename = fn;
522 strNewFile = filename + ".new";
523
524 QFile f( strNewFile );
525 if ( !f.open( IO_WriteOnly|IO_Raw ) ) {
526 qWarning( "could not open for writing `%s'", strNewFile.latin1() );
527 git = groups.end();
528 return;
529 }
530
531 QString str;
532 QCString cstr;
533 QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin();
534
535 for ( ; g_it != groups.end(); ++g_it ) {
536 str += "[" + g_it.key() + "]\n";
537 KateConfigGroup::Iterator e_it = ( *g_it ).begin();
538 for ( ; e_it != ( *g_it ).end(); ++e_it )
539 str += e_it.key() + " = " + *e_it + "\n";
540 }
541 cstr = str.utf8();
542
543 int total_length;
544 total_length = f.writeBlock( cstr.data(), cstr.length() );
545 if ( total_length != int(cstr.length()) ) {
546 QMessageBox::critical( 0, QObject::tr("Out of Space"),
547 QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") );
548 f.close();
549 QFile::remove( strNewFile );
550 return;
551 }
552
553 f.close();
554 // now rename the file...
555 if ( rename( strNewFile, filename ) < 0 ) {
556 qWarning( "problem renaming the file %s to %s", strNewFile.latin1(),
557 filename.latin1() );
558 QFile::remove( strNewFile );
559 }
560}
561
562/*!
563 Returns whether the KateConfig is in a valid state.
564*/
565bool KateConfig::isValid() const
566{
567 return groups.end() != git;
568}
569
570/*!
571 \internal
572*/
573void KateConfig::read()
574{
575 changed = FALSE;
576
577 if ( !QFileInfo( filename ).exists() ) {
578 git = groups.end();
579 return;
580 }
581
582 QFile f( filename );
583 if ( !f.open( IO_ReadOnly ) ) {
584 git = groups.end();
585 return;
586 }
587
588 QTextStream s( &f );
589#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
590 // The below should work, but doesn't in Qt 2.3.0
591 s.setCodec( QTextCodec::codecForMib( 106 ) );
592#else
593 s.setEncoding( QTextStream::UnicodeUTF8 );
594#endif
595
596 QStringList list = QStringList::split('\n', s.read() );
597 f.close();
598
599 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
600 if ( !parse( *it ) ) {
601 git = groups.end();
602 return;
603 }
604 }
605}
606
607/*!
608 \internal
609*/
610bool KateConfig::parse( const QString &l )
611{
612 QString line = l.stripWhiteSpace();
613
614 if ( line [0] == QChar ( '#' ))
615 return true; // ignore comments
616
617 if ( line[ 0 ] == QChar( '[' ) ) {
618 QString gname = line;
619 gname = gname.remove( 0, 1 );
620 if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) )
621 gname = gname.remove( gname.length() - 1, 1 );
622 git = groups.insert( gname, KateConfigGroup() );
623 } else if ( !line.isEmpty() ) {
624 if ( git == groups.end() )
625 return FALSE;
626 int eq = line.find( '=' );
627 if ( eq == -1 )
628 return FALSE;
629 QString key = line.left(eq).stripWhiteSpace();
630 QString value = line.mid(eq+1).stripWhiteSpace();
631 ( *git ).insert( key, value );
632 }
633 return TRUE;
634}
diff --git a/noncore/apps/tinykate/libkate/kateconfig.h b/noncore/apps/tinykate/libkate/kateconfig.h
new file mode 100644
index 0000000..80a4e67
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/kateconfig.h
@@ -0,0 +1,117 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef KATECONFIG_H
22#define KATECONFIG_H
23
24// ##### could use QSettings with Qt 3.0
25
26#include <qmap.h>
27#include <qstringlist.h>
28#include <qfont.h>
29#include <qcolor.h>
30
31class KateConfigPrivate;
32class KateConfig
33{
34public:
35 typedef QMap< QString, QString > KateConfigGroup;
36
37 enum Domain { File, User };
38 KateConfig( const QString &name, Domain domain=User );
39 ~KateConfig();
40
41 bool operator == ( const KateConfig & other ) const { return (filename == other.filename); }
42 bool operator != ( const KateConfig & other ) const { return (filename != other.filename); }
43
44 bool isValid() const;
45 bool hasKey( const QString &key ) const;
46
47 // inline for better SharpROM BC
48 inline bool hasGroup ( const QString &gname ) const { return ( groups. find ( gname ) != groups. end ( )); };
49 inline QStringList groupList ( ) const { QStringList sl; for ( QMap< QString, KateConfigGroup >::ConstIterator it = groups. begin ( ); it != groups. end ( ); ++it ) { sl << it.key(); } return sl; };
50
51 void setGroup( const QString &gname );
52 void writeEntry( const QString &key, const char* value );
53 void writeEntry( const QString &key, const QString &value );
54 void writeEntryCrypt( const QString &key, const QString &value );
55 void writeEntry( const QString &key, int num );
56 void writeEntry( const QString &key, unsigned int num );
57#ifdef Q_HAS_BOOL_TYPE
58 void writeEntry( const QString &key, bool b );
59#endif
60 void writeEntry( const QString &key, const QStringList &lst, const QChar &sep );
61 void writeEntry( const QString &key, const QColor & );
62 void writeEntry( const QString &key, const QFont & );
63 void removeEntry( const QString &key );
64
65 QString readEntry( const QString &key, const QString &deflt = QString::null ) const;
66 QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const;
67 QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const;
68 int readNumEntry( const QString &key, int deflt = -1 ) const;
69 bool readBoolEntry( const QString &key, bool deflt = FALSE ) const;
70 QStringList readListEntry( const QString &key, const QChar &sep ) const;
71 QColor readColorEntry( const QString &, const QColor & ) const;
72 QFont readFontEntry( const QString &, const QFont & ) const;
73 QValueList<int> readIntListEntry( const QString &key ) const;
74
75 // For compatibility, non-const versions.
76 QString readEntry( const QString &key, const QString &deflt );
77 QString readEntryCrypt( const QString &key, const QString &deflt );
78 QString readEntryDirect( const QString &key, const QString &deflt );
79 int readNumEntry( const QString &key, int deflt );
80 bool readBoolEntry( const QString &key, bool deflt );
81 QStringList readListEntry( const QString &key, const QChar &sep );
82
83 void clearGroup();
84
85 void write( const QString &fn = QString::null );
86
87protected:
88 void read();
89 bool parse( const QString &line );
90
91 QMap< QString, KateConfigGroup > groups;
92 QMap< QString, KateConfigGroup >::Iterator git;
93 QString filename;
94 QString lang;
95 QString glang;
96 bool changed;
97 KateConfigPrivate *d;
98 static QString configFilename(const QString& name, Domain);
99
100private: // Sharp ROM compatibility
101 KateConfig( const QString &name, bool what );
102};
103
104inline QString KateConfig::readEntry( const QString &key, const QString &deflt ) const
105{ return ((KateConfig*)this)->readEntry(key,deflt); }
106inline QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const
107{ return ((KateConfig*)this)->readEntryCrypt(key,deflt); }
108inline QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const
109{ return ((KateConfig*)this)->readEntryDirect(key,deflt); }
110inline int KateConfig::readNumEntry( const QString &key, int deflt ) const
111{ return ((KateConfig*)this)->readNumEntry(key,deflt); }
112inline bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const
113{ return ((KateConfig*)this)->readBoolEntry(key,deflt); }
114inline QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const
115{ return ((KateConfig*)this)->readListEntry(key,sep); }
116
117#endif
diff --git a/noncore/apps/tinykate/libkate/libkate.pro b/noncore/apps/tinykate/libkate/libkate.pro
index b0354e6..0082106 100644
--- a/noncore/apps/tinykate/libkate/libkate.pro
+++ b/noncore/apps/tinykate/libkate/libkate.pro
@@ -1,7 +1,7 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 HEADERS = microkde/kapplication.h \ 3 HEADERS = microkde/kapplication.h \
4 microkde/kconfig.h \ 4 kateconfig.h \
5 microkde/kdebug.h \ 5 microkde/kdebug.h \
6 microkde/kdialog.h \ 6 microkde/kdialog.h \
7 microkde/kdialogbase.h \ 7 microkde/kdialogbase.h \
@@ -14,7 +14,6 @@ HEADERS = microkde/kapplication.h \
14 microkde/kprinter.h \ 14 microkde/kprinter.h \
15 microkde/krestrictedline.h \ 15 microkde/krestrictedline.h \
16 microkde/kseparator.h \ 16 microkde/kseparator.h \
17 microkde/ksimpleconfig.h \
18 microkde/kstandarddirs.h \ 17 microkde/kstandarddirs.h \
19 microkde/ktempfile.h \ 18 microkde/ktempfile.h \
20 microkde/kunload.h \ 19 microkde/kunload.h \
@@ -45,7 +44,7 @@ HEADERS = microkde/kapplication.h \
45 44
46 SOURCES = microkde/kapplication.cpp \ 45 SOURCES = microkde/kapplication.cpp \
47 microkde/kdialogbase.cpp \ 46 microkde/kdialogbase.cpp \
48 microkde/kconfig.cpp \ 47 kateconfig.cpp \
49 microkde/klocale.cpp \ 48 microkde/klocale.cpp \
50 microkde/kmessagebox.cpp \ 49 microkde/kmessagebox.cpp \
51 microkde/kprocess.cpp \ 50 microkde/kprocess.cpp \
@@ -74,7 +73,9 @@ SOURCES = microkde/kapplication.cpp \
74 interfaces/interfaces.cpp 73 interfaces/interfaces.cpp
75 74
76 INTERFACES= 75 INTERFACES=
77 INCLUDEPATH+= $(OPIEDIR)/include $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ 76 INCLUDEPATH+= $(OPIEDIR)/include \
77 $(OPIEDIR)/noncore/apps/tinykate/libkate \
78 $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \
78 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ 79 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \
79 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ 80 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \
80 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ 81 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \
diff --git a/noncore/apps/tinykate/libkate/microkde/kconfig.cpp b/noncore/apps/tinykate/libkate/microkde/kconfig.cpp
deleted file mode 100644
index d88bda0..0000000
--- a/noncore/apps/tinykate/libkate/microkde/kconfig.cpp
+++ b/dev/null
@@ -1,181 +0,0 @@
1#include <qfile.h>
2#include <qtextstream.h>
3
4#include "kdebug.h"
5
6#include "kconfig.h"
7
8QString KConfig::mGroup = "";
9//QString KConfig::mGroup = "General";
10
11KConfig::KConfig( const QString &fileName )
12 : mFileName( fileName ), mDirty( false )
13{
14 kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl;
15
16 load();
17}
18
19
20KConfig::~KConfig()
21{
22 sync();
23}
24
25void KConfig::setGroup( const QString &group )
26{
27 return;
28
29// kdDebug() << "KConfig::setGroup(): '" << group << "'" << endl;
30
31 mGroup = group;
32
33 if ( mGroup.right( 1 ) != "/" ) mGroup += "/";
34}
35
36
37QValueList<int> KConfig::readIntListEntry( const QString & )
38{
39 QValueList<int> l;
40 return l;
41}
42
43int KConfig::readNumEntry( const QString &, int def )
44{
45 return def;
46}
47
48QString KConfig::readEntry( const QString &key, const QString &def )
49{
50 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
51
52 if ( it == mStringMap.end() ) {
53 return def;
54 }
55
56 return *it;
57}
58
59QStringList KConfig::readListEntry( const QString & )
60{
61 return QStringList();
62}
63
64bool KConfig::readBoolEntry( const QString &key, bool def )
65{
66 QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key );
67
68 if ( it == mBoolMap.end() ) {
69 return def;
70 }
71
72 return *it;
73}
74
75QColor KConfig::readColorEntry( const QString &, QColor *def )
76{
77 if ( def ) return *def;
78 return QColor();
79}
80
81QFont KConfig::readFontEntry( const QString &, QFont *def )
82{
83 if ( def ) return *def;
84 return QFont();
85}
86
87
88void KConfig::writeEntry( const QString &, QValueList<int> )
89{
90}
91
92void KConfig::writeEntry( const QString &, int )
93{
94}
95
96void KConfig::writeEntry( const QString &key, const QString &value )
97{
98 mStringMap.insert( mGroup + key, value );
99
100 mDirty = true;
101}
102
103void KConfig::writeEntry( const QString &, const QStringList & )
104{
105}
106
107void KConfig::writeEntry( const QString &key, bool value)
108{
109 mBoolMap.insert( mGroup + key, value );
110
111 mDirty = true;
112}
113
114void KConfig::writeEntry( const QString &, const QColor & )
115{
116}
117
118void KConfig::writeEntry( const QString &, const QFont & )
119{
120}
121
122void KConfig::load()
123{
124 mBoolMap.clear();
125 mStringMap.clear();
126
127 QFile f( mFileName );
128 if ( !f.open( IO_ReadOnly ) ) {
129 kdDebug() << "KConfig::load(): Can't open file '" << mFileName << "'"
130 << endl;
131 return;
132 }
133
134
135 QTextStream t( &f );
136
137 QString line = t.readLine();
138
139 while ( !line.isNull() ) {
140 QStringList tokens = QStringList::split( ",", line );
141 if ( tokens[0] == "bool" ) {
142 bool value = false;
143 if ( tokens[2] == "1" ) value = true;
144
145 mBoolMap.insert( tokens[1], value );
146 } else if ( tokens[0] == "QString" ) {
147 QString value = tokens[2];
148 mStringMap.insert( tokens[1], value );
149 }
150
151 line = t.readLine();
152 }
153}
154
155void KConfig::sync()
156{
157 if ( !mDirty ) return;
158
159 QFile f( mFileName );
160 if ( !f.open( IO_WriteOnly ) ) {
161 kdDebug() << "KConfig::sync(): Can't open file '" << mFileName << "'"
162 << endl;
163 return;
164 }
165
166 QTextStream t( &f );
167
168 QMap<QString,bool>::ConstIterator itBool;
169 for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) {
170 t << "bool," << itBool.key() << "," << (*itBool ) << endl;
171 }
172
173 QMap<QString,QString>::ConstIterator itString;
174 for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) {
175 t << "QString," << itString.key() << "," << (*itString ) << endl;
176 }
177
178 f.close();
179
180 mDirty = false;
181}
diff --git a/noncore/apps/tinykate/libkate/microkde/kconfig.h b/noncore/apps/tinykate/libkate/microkde/kconfig.h
deleted file mode 100644
index 8bd768a..0000000
--- a/noncore/apps/tinykate/libkate/microkde/kconfig.h
+++ b/dev/null
@@ -1,51 +0,0 @@
1#ifndef MINIKDE_KCONFIG_H
2#define MINIKDE_KCONFIG_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6#include <qvaluelist.h>
7#include <qcolor.h>
8#include <qfont.h>
9#include <qmap.h>
10
11class KConfig
12{
13 public:
14 KConfig( const QString & );
15 ~KConfig();
16
17 void setGroup( const QString & );
18
19 bool hasGroup( const QString &) {return false;}
20
21 QValueList<int> readIntListEntry( const QString & );
22 int readNumEntry( const QString &, int def=0 );
23 QString readEntry( const QString &, const QString &def=QString::null );
24 QStringList readListEntry( const QString & );
25 bool readBoolEntry( const QString &, bool def=false );
26 QColor readColorEntry( const QString &, QColor * );
27 QFont readFontEntry( const QString &, QFont * );
28
29 void writeEntry( const QString &, QValueList<int> );
30 void writeEntry( const QString &, int );
31 void writeEntry( const QString &, const QString & );
32 void writeEntry( const QString &, const QStringList & );
33 void writeEntry( const QString &, bool );
34 void writeEntry( const QString &, const QColor & );
35 void writeEntry( const QString &, const QFont & );
36
37 void load();
38 void sync();
39
40 private:
41 static QString mGroup;
42
43 QString mFileName;
44
45 QMap<QString,bool> mBoolMap;
46 QMap<QString,QString> mStringMap;
47
48 bool mDirty;
49};
50
51#endif
diff --git a/noncore/apps/tinykate/libkate/microkde/kglobal.cpp b/noncore/apps/tinykate/libkate/microkde/kglobal.cpp
index 572768d..9b5c4d3 100644
--- a/noncore/apps/tinykate/libkate/microkde/kglobal.cpp
+++ b/noncore/apps/tinykate/libkate/microkde/kglobal.cpp
@@ -1,7 +1,7 @@
1#include "kglobal.h" 1#include "kglobal.h"
2 2
3KLocale *KGlobal::mLocale = 0; 3KLocale *KGlobal::mLocale = 0;
4KConfig *KGlobal::mConfig = 0; 4KateConfig *KGlobal::mConfig = 0;
5KIconLoader *KGlobal::mIconLoader = 0; 5KIconLoader *KGlobal::mIconLoader = 0;
6KStandardDirs *KGlobal::mDirs = 0; 6KStandardDirs *KGlobal::mDirs = 0;
7 7
@@ -16,10 +16,10 @@ KLocale *KGlobal::locale()
16 return mLocale; 16 return mLocale;
17} 17}
18 18
19KConfig *KGlobal::config() 19KateConfig *KGlobal::config()
20{ 20{
21 if ( !mConfig ) { 21 if ( !mConfig ) {
22 mConfig = new KConfig( KStandardDirs::appDir() + mAppName + "rc" ); 22 mConfig = new KateConfig( mAppName );
23 } 23 }
24 24
25 return mConfig; 25 return mConfig;
diff --git a/noncore/apps/tinykate/libkate/microkde/kglobal.h b/noncore/apps/tinykate/libkate/microkde/kglobal.h
index 8985bd4..e4e2c79 100644
--- a/noncore/apps/tinykate/libkate/microkde/kglobal.h
+++ b/noncore/apps/tinykate/libkate/microkde/kglobal.h
@@ -4,12 +4,12 @@
4#include "klocale.h" 4#include "klocale.h"
5#include "kiconloader.h" 5#include "kiconloader.h"
6#include "kstandarddirs.h" 6#include "kstandarddirs.h"
7#include "kconfig.h" 7#include <kateconfig.h>
8 8
9class KGlobal { 9class KGlobal {
10 public: 10 public:
11 static KLocale *locale(); 11 static KLocale *locale();
12 static KConfig *config(); 12 static KateConfig *config();
13 static KIconLoader *iconLoader(); 13 static KIconLoader *iconLoader();
14 static KStandardDirs *dirs(); 14 static KStandardDirs *dirs();
15 15
@@ -17,7 +17,7 @@ class KGlobal {
17 17
18 private: 18 private:
19 static KLocale *mLocale; 19 static KLocale *mLocale;
20 static KConfig *mConfig; 20 static KateConfig *mConfig;
21 static KIconLoader *mIconLoader; 21 static KIconLoader *mIconLoader;
22 static KStandardDirs *mDirs; 22 static KStandardDirs *mDirs;
23 23
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp
index 63e941f..af3b30d 100644
--- a/noncore/apps/tinykate/libkate/view/kateview.cpp
+++ b/noncore/apps/tinykate/libkate/view/kateview.cpp
@@ -46,6 +46,7 @@
46#include "../document/katehighlight.h" 46#include "../document/katehighlight.h"
47#include "kateviewdialog.h" 47#include "kateviewdialog.h"
48#include "../document/katedialogs.h" 48#include "../document/katedialogs.h"
49#include <kateconfig.h>
49 50
50#include <qfocusdata.h> 51#include <qfocusdata.h>
51#include <kdebug.h> 52#include <kdebug.h>
@@ -56,7 +57,6 @@
56#include <kpopupmenu.h> 57#include <kpopupmenu.h>
57#include <qkeycode.h> 58#include <qkeycode.h>
58#include <qintdict.h> 59#include <qintdict.h>
59#include <kconfig.h>
60#include <qfont.h> 60#include <qfont.h>
61#include <qpainter.h> 61#include <qpainter.h>
62#include <qpixmap.h> 62#include <qpixmap.h>
@@ -1241,12 +1241,12 @@ KateView::KateView(KateDocument *doc, QWidget *parent, const char * name) : Kate
1241 1241
1242KateView::~KateView() 1242KateView::~KateView()
1243{ 1243{
1244 writeConfig();
1244 1245
1245 if (myDoc && !myDoc->m_bSingleViewMode) 1246 if (myDoc && !myDoc->m_bSingleViewMode)
1246 myDoc->removeView( this ); 1247 myDoc->removeView( this );
1247 1248
1248 delete myViewInternal; 1249 delete myViewInternal;
1249
1250} 1250}
1251 1251
1252#if 0 1252#if 0
@@ -2222,27 +2222,27 @@ void KateView::installPopup(QPopupMenu *rmb_Menu)
2222 2222
2223void KateView::readConfig() 2223void KateView::readConfig()
2224{ 2224{
2225 KConfig *config = KGlobal::config(); 2225 KateConfig *config = KGlobal::config();
2226 config->setGroup("Kate View"); 2226 config->setGroup("Kate View");
2227 2227
2228 searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt); 2228 searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt);
2229 configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark; 2229 configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark;
2230 2230
2231 config->sync(); 2231// config->sync();
2232} 2232}
2233 2233
2234void KateView::writeConfig() 2234void KateView::writeConfig()
2235{ 2235{
2236 KConfig *config = KGlobal::config(); 2236 KateConfig *config = KGlobal::config();
2237 config->setGroup("Kate View"); 2237 config->setGroup("Kate View");
2238 2238
2239 config->writeEntry("SearchFlags",searchFlags); 2239 config->writeEntry("SearchFlags",searchFlags);
2240 config->writeEntry("ConfigFlags",configFlags); 2240 config->writeEntry("ConfigFlags",configFlags);
2241 2241
2242 config->sync(); 2242// config->sync();
2243} 2243}
2244 2244
2245void KateView::readSessionConfig(KConfig *config) 2245void KateView::readSessionConfig(KateConfig *config)
2246{ 2246{
2247 PointStruc cursor; 2247 PointStruc cursor;
2248 2248
@@ -2255,7 +2255,7 @@ void KateView::readSessionConfig(KConfig *config)
2255 setIconBorder(myIconBorder); 2255 setIconBorder(myIconBorder);
2256} 2256}
2257 2257
2258void KateView::writeSessionConfig(KConfig *config) 2258void KateView::writeSessionConfig(KateConfig *config)
2259{ 2259{
2260 config->writeEntry("XPos",myViewInternal->xPos); 2260 config->writeEntry("XPos",myViewInternal->xPos);
2261 config->writeEntry("YPos",myViewInternal->yPos); 2261 config->writeEntry("YPos",myViewInternal->yPos);
@@ -2320,7 +2320,7 @@ void KateView::configDialog()
2320 hlManager->getDefaults(defaultStyleList); 2320 hlManager->getDefaults(defaultStyleList);
2321 2321
2322 hlDataList.setAutoDelete(true); 2322 hlDataList.setAutoDelete(true);
2323 //this gets the data from the KConfig object 2323 //this gets the data from the KateConfig object
2324 hlManager->getHlDataList(hlDataList); 2324 hlManager->getHlDataList(hlDataList);
2325 2325
2326 page=kd->addPage(i18n("Highlighting")); 2326 page=kd->addPage(i18n("Highlighting"));
diff --git a/noncore/apps/tinykate/libkate/view/kateview.h b/noncore/apps/tinykate/libkate/view/kateview.h
index 2e78a3a..858e8a1 100644
--- a/noncore/apps/tinykate/libkate/view/kateview.h
+++ b/noncore/apps/tinykate/libkate/view/kateview.h
@@ -49,6 +49,7 @@
49 49
50 50
51class KateDocument; 51class KateDocument;
52class KateConfig;
52class Highlight; 53class Highlight;
53 54
54/* 55/*
@@ -661,14 +662,14 @@ class KateView : public Kate::View
661 */ 662 */
662 void writeConfig(); 663 void writeConfig();
663 /** 664 /**
664 Reads session config out of the KConfig object. This also includes 665 Reads session config out of the KateConfig object. This also includes
665 the actual cursor position and the bookmarks. 666 the actual cursor position and the bookmarks.
666 */ 667 */
667 void readSessionConfig(KConfig *); 668 void readSessionConfig(KateConfig *);
668 /** 669 /**
669 Writes session config into the KConfig object 670 Writes session config into the KateConfig object
670 */ 671 */
671 void writeSessionConfig(KConfig *); 672 void writeSessionConfig(KateConfig *);
672 673
673 674
674 public: 675 public:
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp
index 6164fa5..aecc1bd 100644
--- a/noncore/apps/tinykate/tinykate.cpp
+++ b/noncore/apps/tinykate/tinykate.cpp
@@ -35,6 +35,7 @@
35#include <katedocument.h> 35#include <katedocument.h>
36#include <katehighlight.h> 36#include <katehighlight.h>
37#include <kateview.h> 37#include <kateview.h>
38#include <kglobal.h>
38 39
39TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : 40TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
40 QMainWindow( parent, name, f ) 41 QMainWindow( parent, name, f )
@@ -43,6 +44,7 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
43 currentView=0; 44 currentView=0;
44 viewCount=0; 45 viewCount=0;
45 setCaption(tr("TinyKATE")); 46 setCaption(tr("TinyKATE"));
47 KGlobal::setAppName("TinyKATE");
46 48
47 setToolBarsMovable(FALSE); 49 setToolBarsMovable(FALSE);
48 50
@@ -148,6 +150,14 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
148 150
149} 151}
150 152
153TinyKate::~TinyKate( )
154{
155 qWarning("TinyKate destructor\n");
156 if( KGlobal::config() != 0 ) {
157 qWarning("deleting KateConfig object..\n");
158 delete KGlobal::config();
159 }
160}
151 161
152void TinyKate::slotOpen( ) 162void TinyKate::slotOpen( )
153{ 163{
diff --git a/noncore/apps/tinykate/tinykate.h b/noncore/apps/tinykate/tinykate.h
index 7b61bae..bb32f98 100644
--- a/noncore/apps/tinykate/tinykate.h
+++ b/noncore/apps/tinykate/tinykate.h
@@ -31,9 +31,9 @@ class TinyKate : public QMainWindow
31Q_OBJECT 31Q_OBJECT
32public: 32public:
33 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); 33 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0);
34 ~TinyKate( );
34 35
35public slots: 36public slots:
36 QString currentFileName;
37 void slotNew(); 37 void slotNew();
38 38
39protected slots: 39protected slots:
@@ -45,6 +45,7 @@ protected slots:
45protected: 45protected:
46 void open(const QString&); 46 void open(const QString&);
47private: 47private:
48 QString currentFileName;
48 OTabWidget *tabwidget; 49 OTabWidget *tabwidget;
49 KTextEditor::View *currentView; 50 KTextEditor::View *currentView;
50 51
diff --git a/noncore/apps/tinykate/tinykate.pro b/noncore/apps/tinykate/tinykate.pro
index 61b60a6..632bd49 100644
--- a/noncore/apps/tinykate/tinykate.pro
+++ b/noncore/apps/tinykate/tinykate.pro
@@ -4,7 +4,9 @@ DESTDIR = $(OPIEDIR)/bin
4 HEADERS = tinykate.h 4 HEADERS = tinykate.h
5 SOURCES = tinykate.cpp main.cpp 5 SOURCES = tinykate.cpp main.cpp
6 INTERFACES= 6 INTERFACES=
7 INCLUDEPATH+= $(OPIEDIR)/include $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ 7 INCLUDEPATH+= $(OPIEDIR)/include \
8 $(OPIEDIR)/noncore/apps/tinykate/libkate \
9 $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \
8 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ 10 $(OPIEDIR)/noncore/apps/tinykate/libkate/document \
9 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ 11 $(OPIEDIR)/noncore/apps/tinykate/libkate/view \
10 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ 12 $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \