author | zecke <zecke> | 2004-12-24 23:05:54 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-24 23:05:54 (UTC) |
commit | eb16a7b3d17b0659a7d83900843cef8efb510ceb (patch) (unidiff) | |
tree | 7e493f8b38e9e1a3553d4e87fb36a962acd82c5c | |
parent | d36845f5f7e7d6bd49529524cdc9f39ce1164491 (diff) | |
download | opie-eb16a7b3d17b0659a7d83900843cef8efb510ceb.zip opie-eb16a7b3d17b0659a7d83900843cef8efb510ceb.tar.gz opie-eb16a7b3d17b0659a7d83900843cef8efb510ceb.tar.bz2 |
Config:
Merged:
void writeEntry( const QString &key, const QStringList &lst)
QStringList readListEntry( const QString &key ) const
void removeGroup()
void removeGroup(const QString&)
QStringList allGroups() const
Uninlined:
const versions of read*Entry
bool hasGroup ( const QString &gname )const
QStringList groupList ( )const
Marked these methods as NOT_IN_QPE, NOT_IN_SHARP, QTOPIA_MERGED_METHOD(version)
to make them weak by default and to know which functions needs to be defined
for possible SHARP.ROM versions
-rw-r--r-- | library/config.cpp | 164 | ||||
-rw-r--r-- | library/config.h | 33 | ||||
-rw-r--r-- | library/qpeglobal.h | 3 |
3 files changed, 182 insertions, 18 deletions
diff --git a/library/config.cpp b/library/config.cpp index 664ca34..61ff089 100644 --- a/library/config.cpp +++ b/library/config.cpp | |||
@@ -1,18 +1,18 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000,2004 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
@@ -565,16 +565,178 @@ bool Config::parse( const QString &l ) | |||
565 | gname = gname.remove( 0, 1 ); | 565 | gname = gname.remove( 0, 1 ); |
566 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | 566 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) |
567 | gname = gname.remove( gname.length() - 1, 1 ); | 567 | gname = gname.remove( gname.length() - 1, 1 ); |
568 | git = groups.insert( gname, ConfigGroup() ); | 568 | git = groups.insert( gname, ConfigGroup() ); |
569 | } else if ( !line.isEmpty() ) { | 569 | } else if ( !line.isEmpty() ) { |
570 | if ( git == groups.end() ) | 570 | if ( git == groups.end() ) |
571 | return FALSE; | 571 | return FALSE; |
572 | int eq = line.find( '=' ); | 572 | int eq = line.find( '=' ); |
573 | if ( eq == -1 ) | 573 | if ( eq == -1 ) |
574 | return FALSE; | 574 | return FALSE; |
575 | QString key = line.left(eq).stripWhiteSpace(); | 575 | QString key = line.left(eq).stripWhiteSpace(); |
576 | QString value = line.mid(eq+1).stripWhiteSpace(); | 576 | QString value = line.mid(eq+1).stripWhiteSpace(); |
577 | ( *git ).insert( key, value ); | 577 | ( *git ).insert( key, value ); |
578 | } | 578 | } |
579 | return TRUE; | 579 | return TRUE; |
580 | } | 580 | } |
581 | |||
582 | |||
583 | |||
584 | bool Config::hasGroup( const QString& name )const { | ||
585 | return ( groups. find ( name ) != groups. end ( )); | ||
586 | }; | ||
587 | |||
588 | QStringList Config::groupList()const { | ||
589 | QStringList sl; | ||
590 | for ( ConfigGroupMap::ConstIterator it = groups. begin ( ); it != groups. end ( ); ++it ) | ||
591 | sl << it.key(); | ||
592 | |||
593 | return sl; | ||
594 | }; | ||
595 | |||
596 | ///////////// | ||
597 | // Qtopia 2.1 Functions | ||
598 | // | ||
599 | //////////// | ||
600 | |||
601 | QStringList Config::allGroups()const { | ||
602 | return groupList(); | ||
603 | } | ||
604 | |||
605 | /*! | ||
606 | Returns the time stamp for the config identified by \a name. The | ||
607 | time stamp represents the time the config was last committed to storage. | ||
608 | Returns 0 if there is no time stamp available for the config. | ||
609 | |||
610 | A \a domain can optionally be specified and defaults to User. | ||
611 | See \l{Config()} for details. | ||
612 | |||
613 | First availability: Qtopia 2.0 | ||
614 | */ | ||
615 | long Config::timeStamp(const QString& name, Domain domain) | ||
616 | { | ||
617 | #ifdef Q_WS_WIN | ||
618 | // Too slow (many conversions too and from time_t and QDataTime) | ||
619 | QDateTime epoch; | ||
620 | epoch.setTime_t(0); | ||
621 | return epoch.secsTo(QFileInfo(Config::configFilename(name,domain)).lastModified()); | ||
622 | #else | ||
623 | QString fn = Config::configFilename(name,domain); | ||
624 | struct stat b; | ||
625 | if (lstat( QFile::encodeName(fn).data(), &b ) == 0) | ||
626 | return b.st_mtime; | ||
627 | else | ||
628 | return 0; | ||
629 | #endif | ||
630 | } | ||
631 | |||
632 | |||
633 | /*! | ||
634 | Removes the current group (and all its entries). | ||
635 | |||
636 | The current group becomes unset. | ||
637 | |||
638 | First availability: Qtopia 2.0 | ||
639 | */ | ||
640 | void Config::removeGroup() | ||
641 | { | ||
642 | if ( git == groups.end() ) { | ||
643 | qWarning( "no group set" ); | ||
644 | return; | ||
645 | } | ||
646 | |||
647 | groups.remove(git.key()); | ||
648 | git = groups.end(); | ||
649 | changed = TRUE; | ||
650 | } | ||
651 | |||
652 | /*! | ||
653 | Removes the current group (and all its entries). | ||
654 | |||
655 | The current group becomes unset. | ||
656 | |||
657 | First availability: Qtopia 2.0 | ||
658 | */ | ||
659 | void Config::removeGroup(const QString& g) | ||
660 | { | ||
661 | groups.remove(g); | ||
662 | git = groups.end(); | ||
663 | } | ||
664 | |||
665 | |||
666 | |||
667 | /*! | ||
668 | Writes a (\a key, \a lst) entry to the current group. | ||
669 | |||
670 | The list is | ||
671 | separated by the two characters "^e", and "^" withing the strings | ||
672 | is replaced by "^^", such that the strings may contain any character, | ||
673 | including "^". | ||
674 | |||
675 | Null strings are also allowed, and are recorded as "^0" in the string. | ||
676 | |||
677 | First availability: Qtopia 2.0 | ||
678 | |||
679 | \sa readListEntry() | ||
680 | */ | ||
681 | void Config::writeEntry( const QString &key, const QStringList &lst ) | ||
682 | { | ||
683 | QString s; | ||
684 | for (QStringList::ConstIterator it=lst.begin(); it!=lst.end(); ++it) { | ||
685 | QString el = *it; | ||
686 | if ( el.isNull() ) { | ||
687 | el = "^0"; | ||
688 | } else { | ||
689 | el.replace(QRegExp("\\^"), "^^"); | ||
690 | } | ||
691 | s+=el; | ||
692 | s+="^e"; // end of element | ||
693 | } | ||
694 | writeEntry(key, s); | ||
695 | } | ||
696 | |||
697 | /*! | ||
698 | Returns the string list entry stored using \a key and with | ||
699 | the escaped seperator convention described in writeListEntry(). | ||
700 | |||
701 | First availability: Qtopia 2.0 | ||
702 | */ | ||
703 | QStringList Config::readListEntry( const QString &key ) const | ||
704 | { | ||
705 | QString value = readEntry( key, QString::null ); | ||
706 | QStringList l; | ||
707 | QString s; | ||
708 | bool esc=FALSE; | ||
709 | for (int i=0; i<(int)value.length(); i++) { | ||
710 | if ( esc ) { | ||
711 | if ( value[i] == 'e' ) { // end-of-string | ||
712 | l.append(s); | ||
713 | s=""; | ||
714 | } else if ( value[i] == '0' ) { // null string | ||
715 | s=QString::null; | ||
716 | } else { | ||
717 | s.append(value[i]); | ||
718 | } | ||
719 | esc = FALSE; | ||
720 | } else if ( value[i] == '^' ) { | ||
721 | esc = TRUE; | ||
722 | } else { | ||
723 | s.append(value[i]); | ||
724 | if ( i == (int)value.length()-1 ) | ||
725 | l.append(s); | ||
726 | } | ||
727 | } | ||
728 | return l; | ||
729 | } | ||
730 | |||
731 | QString Config::readEntry( const QString &key, const QString &deflt ) const | ||
732 | { return ((Config*)this)->readEntry(key,deflt); } | ||
733 | QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const | ||
734 | { return ((Config*)this)->readEntryCrypt(key,deflt); } | ||
735 | QString Config::readEntryDirect( const QString &key, const QString &deflt ) const | ||
736 | { return ((Config*)this)->readEntryDirect(key,deflt); } | ||
737 | int Config::readNumEntry( const QString &key, int deflt ) const | ||
738 | { return ((Config*)this)->readNumEntry(key,deflt); } | ||
739 | bool Config::readBoolEntry( const QString &key, bool deflt ) const | ||
740 | { return ((Config*)this)->readBoolEntry(key,deflt); } | ||
741 | QStringList Config::readListEntry( const QString &key, const QChar &sep ) const | ||
742 | { return ((Config*)this)->readListEntry(key,sep); } | ||
diff --git a/library/config.h b/library/config.h index a2f9b2d..29ba0d6 100644 --- a/library/config.h +++ b/library/config.h | |||
@@ -1,109 +1,108 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000, 2004 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef CONFIG_H | 21 | #ifndef CONFIG_H |
22 | #define CONFIG_H | 22 | #define CONFIG_H |
23 | 23 | ||
24 | // ##### could use QSettings with Qt 3.0 | 24 | // ##### could use QSettings with Qt 3.0 |
25 | 25 | ||
26 | #include <qpe/qpeglobal.h> | ||
27 | |||
26 | #include <qmap.h> | 28 | #include <qmap.h> |
27 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
28 | 30 | ||
31 | typedef QMap< QString, QString > ConfigGroup; | ||
32 | typedef QMap< QString, ConfigGroup> ConfigGroupMap; | ||
33 | |||
29 | class ConfigPrivate; | 34 | class ConfigPrivate; |
30 | class Config | 35 | class Config |
31 | { | 36 | { |
32 | public: | 37 | public: |
33 | typedef QMap< QString, QString > ConfigGroup; | ||
34 | 38 | ||
35 | enum Domain { File, User }; | 39 | enum Domain { File, User }; |
36 | Config( const QString &name, Domain domain=User ); | 40 | Config( const QString &name, Domain domain=User ); |
37 | ~Config(); | 41 | ~Config(); |
38 | 42 | ||
43 | QTOPIA_MERGED_METHOD(static long timeStamp( const QString &name, Domain domain=User ), "2.1"); | ||
44 | |||
39 | bool operator == ( const Config & other ) const { return (filename == other.filename); } | 45 | bool operator == ( const Config & other ) const { return (filename == other.filename); } |
40 | bool operator != ( const Config & other ) const { return (filename != other.filename); } | 46 | bool operator != ( const Config & other ) const { return (filename != other.filename); } |
41 | 47 | ||
42 | bool isValid() const; | 48 | bool isValid() const; |
43 | bool hasKey( const QString &key ) const; | 49 | bool hasKey( const QString &key ) const; |
44 | 50 | ||
45 | // inline for better SharpROM BC | 51 | // inline for better SharpROM BC |
46 | inline bool hasGroup ( const QString &gname ) const { return ( groups. find ( gname ) != groups. end ( )); }; | 52 | NOT_IN_QPE(bool hasGroup ( const QString &gname ) const); |
47 | inline QStringList groupList ( ) const { QStringList sl; for ( QMap< QString, ConfigGroup >::ConstIterator it = groups. begin ( ); it != groups. end ( ); ++it ) { sl << it.key(); } return sl; }; | 53 | NOT_IN_QPE(QStringList groupList ( ) const); |
48 | 54 | ||
49 | void setGroup( const QString &gname ); | 55 | void setGroup( const QString &gname ); |
50 | void writeEntry( const QString &key, const char* value ); | 56 | void writeEntry( const QString &key, const char* value ); |
51 | void writeEntry( const QString &key, const QString &value ); | 57 | void writeEntry( const QString &key, const QString &value ); |
52 | void writeEntryCrypt( const QString &key, const QString &value ); | 58 | void writeEntryCrypt( const QString &key, const QString &value ); |
53 | void writeEntry( const QString &key, int num ); | 59 | void writeEntry( const QString &key, int num ); |
54 | #ifdef Q_HAS_BOOL_TYPE | 60 | #ifdef Q_HAS_BOOL_TYPE |
55 | void writeEntry( const QString &key, bool b ); | 61 | void writeEntry( const QString &key, bool b ); |
56 | #endif | 62 | #endif |
57 | void writeEntry( const QString &key, const QStringList &lst, const QChar &sep ); | 63 | void writeEntry( const QString &key, const QStringList &lst, const QChar &sep ); |
64 | QTOPIA_MERGED_METHOD(void writeEntry( const QString &key, const QStringList &lst ), "2.1.0"); | ||
65 | |||
58 | void removeEntry( const QString &key ); | 66 | void removeEntry( const QString &key ); |
59 | 67 | ||
60 | QString readEntry( const QString &key, const QString &deflt = QString::null ) const; | 68 | QString readEntry( const QString &key, const QString &deflt = QString::null ) const; |
61 | QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const; | 69 | QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const; |
62 | QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const; | 70 | QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const; |
63 | int readNumEntry( const QString &key, int deflt = -1 ) const; | 71 | int readNumEntry( const QString &key, int deflt = -1 ) const; |
64 | bool readBoolEntry( const QString &key, bool deflt = FALSE ) const; | 72 | bool readBoolEntry( const QString &key, bool deflt = FALSE ) const; |
65 | QStringList readListEntry( const QString &key, const QChar &sep ) const; | 73 | QStringList readListEntry( const QString &key, const QChar &sep ) const; |
74 | QTOPIA_MERGED_METHOD(QStringList readListEntry( const QString &key ) const, "2.1.0"); | ||
66 | 75 | ||
67 | // For compatibility, non-const versions. | 76 | // For compatibility, non-const versions. |
68 | QString readEntry( const QString &key, const QString &deflt ); | 77 | QString readEntry( const QString &key, const QString &deflt ); |
69 | QString readEntryCrypt( const QString &key, const QString &deflt ); | 78 | QString readEntryCrypt( const QString &key, const QString &deflt ); |
70 | QString readEntryDirect( const QString &key, const QString &deflt ); | 79 | QString readEntryDirect( const QString &key, const QString &deflt ); |
71 | int readNumEntry( const QString &key, int deflt ); | 80 | int readNumEntry( const QString &key, int deflt ); |
72 | bool readBoolEntry( const QString &key, bool deflt ); | 81 | bool readBoolEntry( const QString &key, bool deflt ); |
73 | QStringList readListEntry( const QString &key, const QChar &sep ); | 82 | QStringList readListEntry( const QString &key, const QChar &sep ); |
74 | 83 | ||
75 | void clearGroup(); | 84 | void clearGroup(); |
85 | QTOPIA_MERGED_METHOD(void removeGroup(), "2.1.0"); | ||
86 | QTOPIA_MERGED_METHOD(void removeGroup(const QString&), "2.1.0"); | ||
87 | QTOPIA_MERGED_METHOD(QStringList allGroups() const, "2.1.0"); | ||
76 | 88 | ||
77 | void write( const QString &fn = QString::null ); | 89 | void write( const QString &fn = QString::null ); |
78 | 90 | ||
79 | protected: | 91 | protected: |
80 | void read(); | 92 | void read(); |
81 | bool parse( const QString &line ); | 93 | bool parse( const QString &line ); |
82 | 94 | ||
83 | QMap< QString, ConfigGroup > groups; | 95 | QMap< QString, ConfigGroup > groups; |
84 | QMap< QString, ConfigGroup >::Iterator git; | 96 | QMap< QString, ConfigGroup >::Iterator git; |
85 | QString filename; | 97 | QString filename; |
86 | QString lang; | 98 | QString lang; |
87 | QString glang; | 99 | QString glang; |
88 | bool changed; | 100 | bool changed; |
89 | ConfigPrivate *d; | 101 | ConfigPrivate *d; |
90 | static QString configFilename(const QString& name, Domain); | 102 | static QString configFilename(const QString& name, Domain); |
91 | 103 | ||
92 | private: // Sharp ROM compatibility | 104 | private: // Sharp ROM compatibility |
93 | Config( const QString &name, bool what ); | 105 | Config( const QString &name, bool what ); |
94 | }; | 106 | }; |
95 | 107 | ||
96 | inline QString Config::readEntry( const QString &key, const QString &deflt ) const | ||
97 | { return ((Config*)this)->readEntry(key,deflt); } | ||
98 | inline QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const | ||
99 | { return ((Config*)this)->readEntryCrypt(key,deflt); } | ||
100 | inline QString Config::readEntryDirect( const QString &key, const QString &deflt ) const | ||
101 | { return ((Config*)this)->readEntryDirect(key,deflt); } | ||
102 | inline int Config::readNumEntry( const QString &key, int deflt ) const | ||
103 | { return ((Config*)this)->readNumEntry(key,deflt); } | ||
104 | inline bool Config::readBoolEntry( const QString &key, bool deflt ) const | ||
105 | { return ((Config*)this)->readBoolEntry(key,deflt); } | ||
106 | inline QStringList Config::readListEntry( const QString &key, const QChar &sep ) const | ||
107 | { return ((Config*)this)->readListEntry(key,sep); } | ||
108 | |||
109 | #endif | 108 | #endif |
diff --git a/library/qpeglobal.h b/library/qpeglobal.h index a84e435..f64ccfd 100644 --- a/library/qpeglobal.h +++ b/library/qpeglobal.h | |||
@@ -71,18 +71,21 @@ | |||
71 | */ | 71 | */ |
72 | #ifdef GCC_SUPPORTS_VISIBILITY | 72 | #ifdef GCC_SUPPORTS_VISIBILITY |
73 | #undef QPE_EXPORT_SYMBOL | 73 | #undef QPE_EXPORT_SYMBOL |
74 | #define QPE_EXPORT_SYMBOL __attribute__((visibility("default"))) | 74 | #define QPE_EXPORT_SYMBOL __attribute__((visibility("default"))) |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | 77 | ||
78 | 78 | ||
79 | #else // defined(Q_OS_WIN32) | 79 | #else // defined(Q_OS_WIN32) |
80 | #define QPE_WEAK_SYMBOL | 80 | #define QPE_WEAK_SYMBOL |
81 | #define QPE_SYMBOL_USED | 81 | #define QPE_SYMBOL_USED |
82 | #define QPE_SYMBOL_UNUSED | 82 | #define QPE_SYMBOL_UNUSED |
83 | #define QPE_EXPORT_SYMBOL | 83 | #define QPE_EXPORT_SYMBOL |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | 86 | ||
87 | #define QTOPIA_MERGED_METHOD(method, version) method QPE_WEAK_SYMBOL; | ||
88 | #define NOT_IN_SHARP(method) method QPE_WEAK_SYMBOL; | ||
89 | #define NOT_IN_QPE(method) method QPE_WEAK_SYMBOL; | ||
87 | 90 | ||
88 | #endif | 91 | #endif |