-rw-r--r-- | noncore/apps/tinykate/libkate/document/katebuffer.cpp | 89 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 73 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katehighlight.cpp | 126 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp | 69 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/kateconfig.cpp | 219 | ||||
-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 31 |
6 files changed, 314 insertions, 293 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katebuffer.cpp b/noncore/apps/tinykate/libkate/document/katebuffer.cpp index 22a4917..4c15fd0 100644 --- a/noncore/apps/tinykate/libkate/document/katebuffer.cpp +++ b/noncore/apps/tinykate/libkate/document/katebuffer.cpp | |||
@@ -1,177 +1,178 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KWrite | 2 | This file is part of KWrite |
3 | Copyright (c) 2000 Waldo Bastian <bastian@kde.org> | 3 | Copyright (c) 2000 Waldo Bastian <bastian@kde.org> |
4 | Copyright (c) 2002 Joseph Wenninger <jowenn@kde.org> | 4 | Copyright (c) 2002 Joseph Wenninger <jowenn@kde.org> |
5 | 5 | ||
6 | $Id$ | 6 | $Id$ |
7 | 7 | ||
8 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public |
10 | License version 2 as published by the Free Software Foundation. | 10 | License version 2 as published by the Free Software Foundation. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | 23 | ||
24 | #include "katebuffer.h" | 24 | #include "katebuffer.h" |
25 | #include "kdebug.h" | ||
25 | 26 | ||
26 | // Includes for reading file | 27 | /* OPIE */ |
27 | #include <sys/types.h> | 28 | #include <opie2/odebug.h> |
28 | #include <sys/stat.h> | ||
29 | #include <fcntl.h> | ||
30 | #include <errno.h> | ||
31 | #include <unistd.h> | ||
32 | 29 | ||
30 | /* QT */ | ||
33 | #include <qfile.h> | 31 | #include <qfile.h> |
34 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
35 | |||
36 | #include <qtimer.h> | 33 | #include <qtimer.h> |
37 | #include <qtextcodec.h> | 34 | #include <qtextcodec.h> |
38 | 35 | ||
39 | // | 36 | /* STD */ |
40 | 37 | // Includes for reading file | |
38 | #include <sys/types.h> | ||
39 | #include <sys/stat.h> | ||
40 | #include <fcntl.h> | ||
41 | #include <errno.h> | ||
42 | #include <unistd.h> | ||
41 | #include <assert.h> | 43 | #include <assert.h> |
42 | #include <kdebug.h> | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Create an empty buffer. | 46 | * Create an empty buffer. |
46 | */ | 47 | */ |
47 | KWBuffer::KWBuffer() | 48 | KWBuffer::KWBuffer() |
48 | { | 49 | { |
49 | clear(); | 50 | clear(); |
50 | } | 51 | } |
51 | 52 | ||
52 | void | 53 | void |
53 | KWBuffer::clear() | 54 | KWBuffer::clear() |
54 | { | 55 | { |
55 | m_stringListIt=0; | 56 | m_stringListIt=0; |
56 | m_stringListCurrent=0; | 57 | m_stringListCurrent=0; |
57 | m_stringList.clear(); | 58 | m_stringList.clear(); |
58 | m_lineCount=1; | 59 | m_lineCount=1; |
59 | m_stringListIt = m_stringList.append(new TextLine()); | 60 | m_stringListIt = m_stringList.append(new TextLine()); |
60 | } | 61 | } |
61 | 62 | ||
62 | /** | 63 | /** |
63 | * Insert a file at line @p line in the buffer. | 64 | * Insert a file at line @p line in the buffer. |
64 | */ | 65 | */ |
65 | void | 66 | void |
66 | KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) | 67 | KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) |
67 | { | 68 | { |
68 | if (line) { | 69 | if (line) { |
69 | qDebug("insert File only supports insertion at line 0 == file opening"); | 70 | odebug << "insert File only supports insertion at line 0 == file opening" << oendl; |
70 | return; | 71 | return; |
71 | } | 72 | } |
72 | clear(); | 73 | clear(); |
73 | QFile iofile(file); | 74 | QFile iofile(file); |
74 | iofile.open(IO_ReadOnly); | 75 | iofile.open(IO_ReadOnly); |
75 | QTextStream stream(&iofile); | 76 | QTextStream stream(&iofile); |
76 | stream.setCodec(codec); | 77 | stream.setCodec(codec); |
77 | QString qsl; | 78 | QString qsl; |
78 | int count=0; | 79 | int count=0; |
79 | for (count=0;((qsl=stream.readLine())!=QString::null);count++) | 80 | for (count=0;((qsl=stream.readLine())!=QString::null); count++) |
80 | { | 81 | { |
81 | if (count==0) | 82 | if (count==0) |
82 | { | 83 | { |
83 | (*m_stringListIt)->append(qsl.unicode(),qsl.length()); | 84 | (*m_stringListIt)->append(qsl.unicode(),qsl.length()); |
84 | } | 85 | } |
85 | else | 86 | else |
86 | { | 87 | { |
87 | TextLine::Ptr tl=new TextLine(); | 88 | TextLine::Ptr tl=new TextLine(); |
88 | tl ->append(qsl.unicode(),qsl.length()); | 89 | tl ->append(qsl.unicode(),qsl.length()); |
89 | m_stringListIt=m_stringList.append(tl); | 90 | m_stringListIt=m_stringList.append(tl); |
90 | } | 91 | } |
91 | } | 92 | } |
92 | if (count!=0) | 93 | if (count!=0) |
93 | { | 94 | { |
94 | m_stringListCurrent=count-1; | 95 | m_stringListCurrent=count-1; |
95 | m_lineCount=count; | 96 | m_lineCount=count; |
96 | } | 97 | } |
97 | } | 98 | } |
98 | 99 | ||
99 | void | 100 | void |
100 | KWBuffer::loadFilePart() | 101 | KWBuffer::loadFilePart() |
101 | { | 102 | { |
102 | } | 103 | } |
103 | 104 | ||
104 | 105 | ||
105 | void | 106 | void |
106 | KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) | 107 | KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) |
107 | { | 108 | { |
108 | } | 109 | } |
109 | 110 | ||
110 | void | 111 | void |
111 | KWBuffer::slotLoadFile() | 112 | KWBuffer::slotLoadFile() |
112 | { | 113 | { |
113 | loadFilePart(); | 114 | loadFilePart(); |
114 | // emit linesChanged(m_totalLines); | 115 | // emit linesChanged(m_totalLines); |
115 | emit linesChanged(20); | 116 | emit linesChanged(20); |
116 | } | 117 | } |
117 | 118 | ||
118 | /** | 119 | /** |
119 | * Return the total number of lines in the buffer. | 120 | * Return the total number of lines in the buffer. |
120 | */ | 121 | */ |
121 | int | 122 | int |
122 | KWBuffer::count() | 123 | KWBuffer::count() |
123 | { | 124 | { |
124 | qDebug("m_stringList.count %d",m_stringList.count()); | 125 | odebug << "m_stringList.count " << m_stringList.count() << "" << oendl; |
125 | return m_lineCount; | 126 | return m_lineCount; |
126 | //return m_stringList.count(); | 127 | // return m_stringList.count(); |
127 | // return m_totalLines; | 128 | // return m_totalLines; |
128 | } | 129 | } |
129 | 130 | ||
130 | 131 | ||
131 | void KWBuffer::seek(int i) | 132 | void KWBuffer::seek(int i) |
132 | { | 133 | { |
133 | if (m_stringListCurrent == i) | 134 | if (m_stringListCurrent == i) |
134 | return; | 135 | return; |
135 | while(m_stringListCurrent < i) | 136 | while(m_stringListCurrent < i) |
136 | { | 137 | { |
137 | ++m_stringListCurrent; | 138 | ++m_stringListCurrent; |
138 | ++m_stringListIt; | 139 | ++m_stringListIt; |
139 | } | 140 | } |
140 | while(m_stringListCurrent > i) | 141 | while(m_stringListCurrent > i) |
141 | { | 142 | { |
142 | --m_stringListCurrent; | 143 | --m_stringListCurrent; |
143 | --m_stringListIt; | 144 | --m_stringListIt; |
144 | } | 145 | } |
145 | } | 146 | } |
146 | 147 | ||
147 | 148 | ||
148 | TextLine::Ptr | 149 | TextLine::Ptr |
149 | KWBuffer::line(int i) | 150 | KWBuffer::line(int i) |
150 | { | 151 | { |
151 | if (i>=m_stringList.count()) return 0; | 152 | if (i>=m_stringList.count()) return 0; |
152 | seek(i); | 153 | seek(i); |
153 | return *m_stringListIt; | 154 | return *m_stringListIt; |
154 | } | 155 | } |
155 | 156 | ||
156 | void | 157 | void |
157 | KWBuffer::insertLine(int i, TextLine::Ptr line) | 158 | KWBuffer::insertLine(int i, TextLine::Ptr line) |
158 | { | 159 | { |
159 | seek(i); | 160 | seek(i); |
160 | m_stringListIt = m_stringList.insert(m_stringListIt, line); | 161 | m_stringListIt = m_stringList.insert(m_stringListIt, line); |
161 | m_stringListCurrent = i; | 162 | m_stringListCurrent = i; |
162 | m_lineCount++; | 163 | m_lineCount++; |
163 | } | 164 | } |
164 | 165 | ||
165 | 166 | ||
166 | void | 167 | void |
167 | KWBuffer::removeLine(int i) | 168 | KWBuffer::removeLine(int i) |
168 | { | 169 | { |
169 | seek(i); | 170 | seek(i); |
170 | m_stringListIt = m_stringList.remove(m_stringListIt); | 171 | m_stringListIt = m_stringList.remove(m_stringListIt); |
171 | m_stringListCurrent = i; | 172 | m_stringListCurrent = i; |
172 | m_lineCount--; | 173 | m_lineCount--; |
173 | } | 174 | } |
174 | 175 | ||
175 | void | 176 | void |
176 | KWBuffer::changeLine(int i) | 177 | KWBuffer::changeLine(int i) |
177 | { | 178 | { |
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index 0c742d7..6dc4fd2 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1,103 +1,104 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katedocument.cpp - description | 2 | katedocument.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | 9 | ||
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * * | 13 | * * |
14 | * This program is free software; you can redistribute it and/or modify * | 14 | * This program is free software; you can redistribute it and/or modify * |
15 | * it under the terms of the GNU General Public License as published by * | 15 | * it under the terms of the GNU General Public License as published by * |
16 | * the Free Software Foundation; either version 2 of the License, or * | 16 | * the Free Software Foundation; either version 2 of the License, or * |
17 | * (at your option) any later version. * | 17 | * (at your option) any later version. * |
18 | * * | 18 | * * |
19 | ***************************************************************************/ | 19 | ***************************************************************************/ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 22 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
23 | digisnap@cs.tu-berlin.de | 23 | digisnap@cs.tu-berlin.de |
24 | 24 | ||
25 | This library is free software; you can redistribute it and/or | 25 | This library is free software; you can redistribute it and/or |
26 | modify it under the terms of the GNU Library General Public | 26 | modify it under the terms of the GNU Library General Public |
27 | License as published by the Free Software Foundation; either | 27 | License as published by the Free Software Foundation; either |
28 | version 2 of the License, or (at your option) any later version. | 28 | version 2 of the License, or (at your option) any later version. |
29 | 29 | ||
30 | This library is distributed in the hope that it will be useful, | 30 | This library is distributed in the hope that it will be useful, |
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
33 | Library General Public License for more details. | 33 | Library General Public License for more details. |
34 | 34 | ||
35 | You should have received a copy of the GNU Library General Public License | 35 | You should have received a copy of the GNU Library General Public License |
36 | along with this library; see the file COPYING.LIB. If not, write to | 36 | along with this library; see the file COPYING.LIB. If not, write to |
37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
38 | Boston, MA 02111-1307, USA. | 38 | Boston, MA 02111-1307, USA. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | #include "katedocument.h" | 41 | #include "katedocument.h" |
42 | #include "kmessagebox.h" | ||
43 | #include "kglobal.h" | ||
42 | 44 | ||
45 | //#include "kcharsets.h" | ||
46 | #include "kdebug.h" | ||
47 | //#include "kinstance.h" | ||
43 | 48 | ||
44 | #include <qfileinfo.h> | 49 | #include "kglobalsettings.h" |
45 | #include <qdatetime.h> | 50 | //#include "kaction.h" |
51 | //#include "kstdaction.h" | ||
46 | 52 | ||
47 | #include <kmessagebox.h> | 53 | #include "../view/kateview.h" |
48 | #include <qpe/config.h> | 54 | #include "katebuffer.h" |
49 | #include <qstring.h> | 55 | #include "katetextline.h" |
50 | 56 | ||
51 | #include <sys/time.h> | 57 | #include "katecmd.h" |
52 | #include <unistd.h> | ||
53 | 58 | ||
54 | #include <stdio.h> | 59 | /* OPIE */ |
60 | #include <opie2/odebug.h> | ||
61 | #include <qpe/config.h> | ||
55 | 62 | ||
63 | /* QT */ | ||
64 | #include <qfileinfo.h> | ||
65 | #include <qdatetime.h> | ||
66 | #include <qstring.h> | ||
56 | #include <qtimer.h> | 67 | #include <qtimer.h> |
57 | #include <qobject.h> | 68 | #include <qobject.h> |
58 | #include <qapplication.h> | 69 | #include <qapplication.h> |
59 | #include <qclipboard.h> | 70 | #include <qclipboard.h> |
60 | #include <qfont.h> | 71 | #include <qfont.h> |
61 | #include <qpainter.h> | 72 | #include <qpainter.h> |
62 | #include <qfile.h> | 73 | #include <qfile.h> |
63 | #include <qtextstream.h> | 74 | #include <qtextstream.h> |
64 | #include <qtextcodec.h> | 75 | #include <qtextcodec.h> |
65 | #include <kglobal.h> | ||
66 | 76 | ||
67 | //#include <kcharsets.h> | 77 | /* STD */ |
68 | #include <kdebug.h> | 78 | #include <sys/time.h> |
69 | //#include <kinstance.h> | 79 | #include <unistd.h> |
70 | 80 | #include <stdio.h> | |
71 | #include <kglobalsettings.h> | ||
72 | //#include <kaction.h> | ||
73 | //#include <kstdaction.h> | ||
74 | |||
75 | #include "../view/kateview.h" | ||
76 | #include "katebuffer.h" | ||
77 | #include "katetextline.h" | ||
78 | |||
79 | #include "katecmd.h" | ||
80 | 81 | ||
81 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) | 82 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) |
82 | : action(a), cursor(cursor), len(len), text(text) { | 83 | : action(a), cursor(cursor), len(len), text(text) { |
83 | } | 84 | } |
84 | 85 | ||
85 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) | 86 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) |
86 | : start(aStart), action(0L), undoType(type) { | 87 | : start(aStart), action(0L), undoType(type) { |
87 | } | 88 | } |
88 | 89 | ||
89 | KateActionGroup::~KateActionGroup() { | 90 | KateActionGroup::~KateActionGroup() { |
90 | KateAction *current, *next; | 91 | KateAction *current, *next; |
91 | 92 | ||
92 | current = action; | 93 | current = action; |
93 | while (current) { | 94 | while (current) { |
94 | next = current->next; | 95 | next = current->next; |
95 | delete current; | 96 | delete current; |
96 | current = next; | 97 | current = next; |
97 | } | 98 | } |
98 | } | 99 | } |
99 | 100 | ||
100 | void KateActionGroup::insertAction(KateAction *a) { | 101 | void KateActionGroup::insertAction(KateAction *a) { |
101 | a->next = action; | 102 | a->next = action; |
102 | action = a; | 103 | action = a; |
103 | } | 104 | } |
@@ -109,71 +110,71 @@ const char * KateActionGroup::typeName(int type) | |||
109 | switch (type) { | 110 | switch (type) { |
110 | case ugPaste : return "Paste Text"; | 111 | case ugPaste : return "Paste Text"; |
111 | case ugDelBlock : return "Selection Overwrite"; | 112 | case ugDelBlock : return "Selection Overwrite"; |
112 | case ugIndent : return "Indent"; | 113 | case ugIndent : return "Indent"; |
113 | case ugUnindent : return "Unindent"; | 114 | case ugUnindent : return "Unindent"; |
114 | case ugComment : return "Comment"; | 115 | case ugComment : return "Comment"; |
115 | case ugUncomment : return "Uncomment"; | 116 | case ugUncomment : return "Uncomment"; |
116 | case ugReplace : return "Text Replace"; | 117 | case ugReplace : return "Text Replace"; |
117 | case ugSpell : return "Spell Check"; | 118 | case ugSpell : return "Spell Check"; |
118 | case ugInsChar : return "Typing"; | 119 | case ugInsChar : return "Typing"; |
119 | case ugDelChar : return "Delete Text"; | 120 | case ugDelChar : return "Delete Text"; |
120 | case ugInsLine : return "New Line"; | 121 | case ugInsLine : return "New Line"; |
121 | case ugDelLine : return "Delete Line"; | 122 | case ugDelLine : return "Delete Line"; |
122 | } | 123 | } |
123 | return ""; | 124 | return ""; |
124 | } | 125 | } |
125 | 126 | ||
126 | const int KateDocument::maxAttribs = 32; | 127 | const int KateDocument::maxAttribs = 32; |
127 | 128 | ||
128 | QStringList KateDocument::searchForList = QStringList(); | 129 | QStringList KateDocument::searchForList = QStringList(); |
129 | QStringList KateDocument::replaceWithList = QStringList(); | 130 | QStringList KateDocument::replaceWithList = QStringList(); |
130 | 131 | ||
131 | uint KateDocument::uniqueID = 0; | 132 | uint KateDocument::uniqueID = 0; |
132 | 133 | ||
133 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; | 134 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; |
134 | 135 | ||
135 | 136 | ||
136 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, | 137 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, |
137 | QWidget *parentWidget, const char *widgetName, | 138 | QWidget *parentWidget, const char *widgetName, |
138 | QObject *, const char *) | 139 | QObject *, const char *) |
139 | : Kate::Document (), | 140 | : Kate::Document (), |
140 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), | 141 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), |
141 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), | 142 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), |
142 | hlManager(HlManager::self ()) | 143 | hlManager(HlManager::self ()) |
143 | { | 144 | { |
144 | 145 | ||
145 | d(this)->hlSetByUser = false; | 146 | d(this)->hlSetByUser = false; |
146 | PreHighlightedTill=0; | 147 | PreHighlightedTill=0; |
147 | RequestPreHighlightTill=0; | 148 | RequestPreHighlightTill=0; |
148 | 149 | ||
149 | m_bSingleViewMode=bSingleViewMode; | 150 | m_bSingleViewMode=bSingleViewMode; |
150 | m_bBrowserView = bBrowserView; | 151 | m_bBrowserView = bBrowserView; |
151 | 152 | ||
152 | m_url = QString::null; | 153 | m_url = QString::null; |
153 | 154 | ||
154 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports | 155 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports |
155 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) | 156 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) |
156 | 157 | ||
157 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); | 158 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); |
158 | 159 | ||
159 | maxLength = -1; | 160 | maxLength = -1; |
160 | 161 | ||
161 | setFont (KGlobalSettings::generalFont()); | 162 | setFont (KGlobalSettings::generalFont()); |
162 | 163 | ||
163 | myDocID = uniqueID; | 164 | myDocID = uniqueID; |
164 | uniqueID++; | 165 | uniqueID++; |
165 | 166 | ||
166 | myDocName = QString (""); | 167 | myDocName = QString (""); |
167 | fileInfo = new QFileInfo (); | 168 | fileInfo = new QFileInfo (); |
168 | 169 | ||
169 | myCmd = new KateCmd (this); | 170 | myCmd = new KateCmd (this); |
170 | 171 | ||
171 | connect(this,SIGNAL(modifiedChanged()),this,SLOT(slotModChanged())); | 172 | connect(this,SIGNAL(modifiedChanged()),this,SLOT(slotModChanged())); |
172 | 173 | ||
173 | buffer = new KWBuffer; | 174 | buffer = new KWBuffer; |
174 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); | 175 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); |
175 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); | 176 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); |
176 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); | 177 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); |
177 | 178 | ||
178 | colors[0] = KGlobalSettings::baseColor(); | 179 | colors[0] = KGlobalSettings::baseColor(); |
179 | colors[1] = KGlobalSettings::highlightColor(); | 180 | colors[1] = KGlobalSettings::highlightColor(); |
@@ -271,84 +272,84 @@ void KateDocument::doPreHighlight() | |||
271 | PreHighlightedTill = till; | 272 | PreHighlightedTill = till; |
272 | updateLines(from,till); | 273 | updateLines(from,till); |
273 | emit preHighlightChanged(PreHighlightedTill); | 274 | emit preHighlightChanged(PreHighlightedTill); |
274 | if (PreHighlightedTill<RequestPreHighlightTill) | 275 | if (PreHighlightedTill<RequestPreHighlightTill) |
275 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); | 276 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); |
276 | } | 277 | } |
277 | 278 | ||
278 | KateDocument::~KateDocument() | 279 | KateDocument::~KateDocument() |
279 | { | 280 | { |
280 | m_highlight->release(); | 281 | m_highlight->release(); |
281 | writeConfig(); | 282 | writeConfig(); |
282 | 283 | ||
283 | if ( !m_bSingleViewMode ) | 284 | if ( !m_bSingleViewMode ) |
284 | { | 285 | { |
285 | m_views.setAutoDelete( true ); | 286 | m_views.setAutoDelete( true ); |
286 | m_views.clear(); | 287 | m_views.clear(); |
287 | m_views.setAutoDelete( false ); | 288 | m_views.setAutoDelete( false ); |
288 | } | 289 | } |
289 | delete_d(this); | 290 | delete_d(this); |
290 | } | 291 | } |
291 | 292 | ||
292 | void KateDocument::openURL(const QString &filename) | 293 | void KateDocument::openURL(const QString &filename) |
293 | { | 294 | { |
294 | 295 | ||
295 | m_file=filename; | 296 | m_file=filename; |
296 | fileInfo->setFile (m_file); | 297 | fileInfo->setFile (m_file); |
297 | setMTime(); | 298 | setMTime(); |
298 | 299 | ||
299 | if (!fileInfo->exists() || !fileInfo->isReadable()) | 300 | if (!fileInfo->exists() || !fileInfo->isReadable()) |
300 | { | 301 | { |
301 | qDebug("File doesn't exit or couldn't be read"); | 302 | odebug << "File doesn't exit or couldn't be read" << oendl; |
302 | return ; | 303 | return ; |
303 | } | 304 | } |
304 | 305 | ||
305 | buffer->clear(); | 306 | buffer->clear(); |
306 | #warning fixme | 307 | #warning fixme |
307 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); | 308 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); |
308 | qDebug("Telling buffer to open file"); | 309 | odebug << "Telling buffer to open file" << oendl; |
309 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); | 310 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); |
310 | 311 | ||
311 | setMTime(); | 312 | setMTime(); |
312 | 313 | ||
313 | if (myWordWrap) | 314 | if (myWordWrap) |
314 | wrapText (myWordWrapAt); | 315 | wrapText (myWordWrapAt); |
315 | 316 | ||
316 | int hl = hlManager->wildcardFind( m_file ); | 317 | int hl = hlManager->wildcardFind( m_file ); |
317 | 318 | ||
318 | setHighlight(hl); | 319 | setHighlight(hl); |
319 | 320 | ||
320 | updateLines(); | 321 | updateLines(); |
321 | updateViews(); | 322 | updateViews(); |
322 | 323 | ||
323 | emit fileNameChanged(); | 324 | emit fileNameChanged(); |
324 | 325 | ||
325 | return ; | 326 | return ; |
326 | } | 327 | } |
327 | 328 | ||
328 | bool KateDocument::saveFile() | 329 | bool KateDocument::saveFile() |
329 | { | 330 | { |
330 | 331 | ||
331 | QFile f( m_file ); | 332 | QFile f( m_file ); |
332 | if ( !f.open( IO_WriteOnly ) ) | 333 | if ( !f.open( IO_WriteOnly ) ) |
333 | return false; // Error | 334 | return false; // Error |
334 | 335 | ||
335 | QTextStream stream(&f); | 336 | QTextStream stream(&f); |
336 | 337 | ||
337 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers | 338 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers |
338 | #warning fixme | 339 | #warning fixme |
339 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); | 340 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); |
340 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec | 341 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec |
341 | 342 | ||
342 | int maxLine = numLines(); | 343 | int maxLine = numLines(); |
343 | int line = 0; | 344 | int line = 0; |
344 | while(true) | 345 | while(true) |
345 | { | 346 | { |
346 | stream << getTextLine(line)->getString(); | 347 | stream << getTextLine(line)->getString(); |
347 | line++; | 348 | line++; |
348 | if (line >= maxLine) break; | 349 | if (line >= maxLine) break; |
349 | 350 | ||
350 | if (eolMode == KateDocument::eolUnix) stream << "\n"; | 351 | if (eolMode == KateDocument::eolUnix) stream << "\n"; |
351 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; | 352 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; |
352 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; | 353 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; |
353 | }; | 354 | }; |
354 | f.close(); | 355 | f.close(); |
@@ -590,49 +591,49 @@ void KateDocument::setModified(bool m) { | |||
590 | } | 591 | } |
591 | 592 | ||
592 | bool KateDocument::isModified() const { | 593 | bool KateDocument::isModified() const { |
593 | return modified; | 594 | return modified; |
594 | } | 595 | } |
595 | 596 | ||
596 | void KateDocument::readConfig() | 597 | void KateDocument::readConfig() |
597 | { | 598 | { |
598 | KateConfig *config = KGlobal::config(); | 599 | KateConfig *config = KGlobal::config(); |
599 | config->setGroup("Kate Document"); | 600 | config->setGroup("Kate Document"); |
600 | 601 | ||
601 | myWordWrap = config->readBoolEntry("Word Wrap On", false); | 602 | myWordWrap = config->readBoolEntry("Word Wrap On", false); |
602 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); | 603 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); |
603 | if (myWordWrap) | 604 | if (myWordWrap) |
604 | wrapText (myWordWrapAt); | 605 | wrapText (myWordWrapAt); |
605 | 606 | ||
606 | setTabWidth(config->readNumEntry("TabWidth", 8)); | 607 | setTabWidth(config->readNumEntry("TabWidth", 8)); |
607 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); | 608 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); |
608 | m_singleSelection = config->readBoolEntry("SingleSelection", false); | 609 | m_singleSelection = config->readBoolEntry("SingleSelection", false); |
609 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); | 610 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); |
610 | setFont (config->readFontEntry("Font", myFont)); | 611 | setFont (config->readFontEntry("Font", myFont)); |
611 | 612 | ||
612 | colors[0] = config->readColorEntry("Color Background", colors[0]); | 613 | colors[0] = config->readColorEntry("Color Background", colors[0]); |
613 | colors[1] = config->readColorEntry("Color Selected", colors[1]); | 614 | colors[1] = config->readColorEntry("Color Selected", colors[1]); |
614 | 615 | ||
615 | // config->sync(); | 616 | // config->sync(); |
616 | } | 617 | } |
617 | 618 | ||
618 | void KateDocument::writeConfig() | 619 | void KateDocument::writeConfig() |
619 | { | 620 | { |
620 | KateConfig *config = KGlobal::config(); | 621 | KateConfig *config = KGlobal::config(); |
621 | config->setGroup("Kate Document"); | 622 | config->setGroup("Kate Document"); |
622 | config->writeEntry("Word Wrap On", myWordWrap); | 623 | config->writeEntry("Word Wrap On", myWordWrap); |
623 | config->writeEntry("Word Wrap At", myWordWrapAt); | 624 | config->writeEntry("Word Wrap At", myWordWrapAt); |
624 | config->writeEntry("TabWidth", tabChars); | 625 | config->writeEntry("TabWidth", tabChars); |
625 | config->writeEntry("UndoSteps", undoSteps); | 626 | config->writeEntry("UndoSteps", undoSteps); |
626 | config->writeEntry("SingleSelection", m_singleSelection); | 627 | config->writeEntry("SingleSelection", m_singleSelection); |
627 | config->writeEntry("Encoding", myEncoding); | 628 | config->writeEntry("Encoding", myEncoding); |
628 | config->writeEntry("Font", myFont); | 629 | config->writeEntry("Font", myFont); |
629 | config->writeEntry("Color Background", colors[0]); | 630 | config->writeEntry("Color Background", colors[0]); |
630 | config->writeEntry("Color Selected", colors[1]); | 631 | config->writeEntry("Color Selected", colors[1]); |
631 | // config->sync(); | 632 | // config->sync(); |
632 | } | 633 | } |
633 | 634 | ||
634 | void KateDocument::readSessionConfig(KateConfig *config) | 635 | void KateDocument::readSessionConfig(KateConfig *config) |
635 | { | 636 | { |
636 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) | 637 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) |
637 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); | 638 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); |
638 | // anders: restore bookmarks if possible | 639 | // anders: restore bookmarks if possible |
@@ -662,49 +663,49 @@ void KateDocument::writeSessionConfig(KateConfig *config) | |||
662 | #endif | 663 | #endif |
663 | } | 664 | } |
664 | 665 | ||
665 | 666 | ||
666 | void KateDocument::setHighlight(int n) { | 667 | void KateDocument::setHighlight(int n) { |
667 | Highlight *h; | 668 | Highlight *h; |
668 | 669 | ||
669 | // hlNumber = n; | 670 | // hlNumber = n; |
670 | 671 | ||
671 | h = hlManager->getHl(n); | 672 | h = hlManager->getHl(n); |
672 | if (h == m_highlight) { | 673 | if (h == m_highlight) { |
673 | updateLines(); | 674 | updateLines(); |
674 | } else { | 675 | } else { |
675 | if (m_highlight != 0L) m_highlight->release(); | 676 | if (m_highlight != 0L) m_highlight->release(); |
676 | h->use(); | 677 | h->use(); |
677 | m_highlight = h; | 678 | m_highlight = h; |
678 | makeAttribs(); | 679 | makeAttribs(); |
679 | } | 680 | } |
680 | PreHighlightedTill=0; | 681 | PreHighlightedTill=0; |
681 | RequestPreHighlightTill=0; | 682 | RequestPreHighlightTill=0; |
682 | emit(highlightChanged()); | 683 | emit(highlightChanged()); |
683 | } | 684 | } |
684 | 685 | ||
685 | void KateDocument::makeAttribs() { | 686 | void KateDocument::makeAttribs() { |
686 | qDebug("KateDocument::makeAttribs()"); | 687 | odebug << "KateDocument::makeAttribs()" << oendl; |
687 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); | 688 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); |
688 | updateFontData(); | 689 | updateFontData(); |
689 | updateLines(); | 690 | updateLines(); |
690 | } | 691 | } |
691 | 692 | ||
692 | void KateDocument::updateFontData() { | 693 | void KateDocument::updateFontData() { |
693 | int maxAscent, maxDescent; | 694 | int maxAscent, maxDescent; |
694 | int tabWidth; | 695 | int tabWidth; |
695 | KateView *view; | 696 | KateView *view; |
696 | 697 | ||
697 | maxAscent = myFontMetrics.ascent(); | 698 | maxAscent = myFontMetrics.ascent(); |
698 | maxDescent = myFontMetrics.descent(); | 699 | maxDescent = myFontMetrics.descent(); |
699 | tabWidth = myFontMetrics.width(' '); | 700 | tabWidth = myFontMetrics.width(' '); |
700 | 701 | ||
701 | fontHeight = maxAscent + maxDescent + 1; | 702 | fontHeight = maxAscent + maxDescent + 1; |
702 | fontAscent = maxAscent; | 703 | fontAscent = maxAscent; |
703 | m_tabWidth = tabChars*tabWidth; | 704 | m_tabWidth = tabChars*tabWidth; |
704 | 705 | ||
705 | for (view = views.first(); view != 0L; view = views.next() ) { | 706 | for (view = views.first(); view != 0L; view = views.next() ) { |
706 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); | 707 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); |
707 | view->tagAll(); | 708 | view->tagAll(); |
708 | view->updateCursor(); | 709 | view->updateCursor(); |
709 | } | 710 | } |
710 | } | 711 | } |
@@ -1902,50 +1903,50 @@ void KateDocument::tagAll() { | |||
1902 | } | 1903 | } |
1903 | 1904 | ||
1904 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { | 1905 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { |
1905 | TextLine::Ptr textLine; | 1906 | TextLine::Ptr textLine; |
1906 | int line, last_line; | 1907 | int line, last_line; |
1907 | int ctxNum, endCtx; | 1908 | int ctxNum, endCtx; |
1908 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; | 1909 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; |
1909 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; | 1910 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; |
1910 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; | 1911 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; |
1911 | last_line = lastLine(); | 1912 | last_line = lastLine(); |
1912 | // if (endLine >= last_line) endLine = last_line; | 1913 | // if (endLine >= last_line) endLine = last_line; |
1913 | 1914 | ||
1914 | line = startLine; | 1915 | line = startLine; |
1915 | ctxNum = 0; | 1916 | ctxNum = 0; |
1916 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); | 1917 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); |
1917 | do { | 1918 | do { |
1918 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; | 1919 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; |
1919 | textLine = getTextLine(line); | 1920 | textLine = getTextLine(line); |
1920 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; | 1921 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; |
1921 | if (line <= endLine && line != cursorY) { | 1922 | if (line <= endLine && line != cursorY) { |
1922 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); | 1923 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); |
1923 | updateMaxLength(textLine); | 1924 | updateMaxLength(textLine); |
1924 | } | 1925 | } |
1925 | endCtx = textLine->getContext(); | 1926 | endCtx = textLine->getContext(); |
1926 | // qDebug("DOHIGHLIGHT"); | 1927 | // odebug << "DOHIGHLIGHT" << oendl; |
1927 | 1928 | ||
1928 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); | 1929 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); |
1929 | textLine->setContext(ctxNum); | 1930 | textLine->setContext(ctxNum); |
1930 | line++; | 1931 | line++; |
1931 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); | 1932 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); |
1932 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; | 1933 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; |
1933 | tagLines(startLine, line - 1); | 1934 | tagLines(startLine, line - 1); |
1934 | } | 1935 | } |
1935 | 1936 | ||
1936 | 1937 | ||
1937 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { | 1938 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { |
1938 | int len; | 1939 | int len; |
1939 | 1940 | ||
1940 | len = textWidth(textLine,textLine->length()); | 1941 | len = textWidth(textLine,textLine->length()); |
1941 | 1942 | ||
1942 | if (len > maxLength) { | 1943 | if (len > maxLength) { |
1943 | longestLine = textLine; | 1944 | longestLine = textLine; |
1944 | maxLength = len; | 1945 | maxLength = len; |
1945 | newDocGeometry = true; | 1946 | newDocGeometry = true; |
1946 | } else { | 1947 | } else { |
1947 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { | 1948 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { |
1948 | maxLength = -1; | 1949 | maxLength = -1; |
1949 | for (int i = 0; i < numLines();i++) { | 1950 | for (int i = 0; i < numLines();i++) { |
1950 | textLine = getTextLine(i); | 1951 | textLine = getTextLine(i); |
1951 | len = textWidth(textLine,textLine->length()); | 1952 | len = textWidth(textLine,textLine->length()); |
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.cpp b/noncore/apps/tinykate/libkate/document/katehighlight.cpp index 0d2c283..539d356 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.cpp +++ b/noncore/apps/tinykate/libkate/document/katehighlight.cpp | |||
@@ -1,65 +1,69 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 2 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
3 | digisnap@cs.tu-berlin.de | 3 | digisnap@cs.tu-berlin.de |
4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> | 4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> |
5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> | 5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> |
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <string.h> | ||
23 | |||
24 | #include <qtextstream.h> | ||
25 | #include <qpe/config.h> | ||
26 | #include <kglobal.h> | ||
27 | //#include <kinstance.h> | ||
28 | //#include <kmimemagic.h> | ||
29 | #include <klocale.h> | ||
30 | //#include <kregexp.h> | ||
31 | #include <kglobalsettings.h> | ||
32 | #include <kdebug.h> | ||
33 | #include <kstddirs.h> | ||
34 | |||
35 | #include "katehighlight.h" | 22 | #include "katehighlight.h" |
36 | |||
37 | |||
38 | #include "katetextline.h" | 23 | #include "katetextline.h" |
39 | #include "katedocument.h" | 24 | #include "katedocument.h" |
40 | #include "katesyntaxdocument.h" | 25 | #include "katesyntaxdocument.h" |
41 | 26 | ||
27 | #include "kglobal.h" | ||
28 | //#include "kinstance.h" | ||
29 | //#include "kmimemagic.h" | ||
30 | #include "klocale.h" | ||
31 | //#include "kregexp.h" | ||
32 | #include "kglobalsettings.h" | ||
33 | #include "kdebug.h" | ||
34 | #include "kstddirs.h" | ||
35 | |||
36 | /* OPIE */ | ||
37 | #include <opie2/odebug.h> | ||
38 | #include <qpe/config.h> | ||
39 | |||
40 | /* QT */ | ||
41 | #include <qtextstream.h> | ||
42 | |||
43 | /* STD */ | ||
44 | #include <string.h> | ||
45 | |||
42 | 46 | ||
43 | HlManager *HlManager::s_pSelf = 0; | 47 | HlManager *HlManager::s_pSelf = 0; |
44 | 48 | ||
45 | enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers}; | 49 | enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers}; |
46 | 50 | ||
47 | static bool trueBool = true; | 51 | static bool trueBool = true; |
48 | static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\"); | 52 | static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\"); |
49 | 53 | ||
50 | int getDefStyleNum(QString name) | 54 | int getDefStyleNum(QString name) |
51 | { | 55 | { |
52 | if (name=="dsNormal") return dsNormal; | 56 | if (name=="dsNormal") return dsNormal; |
53 | if (name=="dsKeyword") return dsKeyword; | 57 | if (name=="dsKeyword") return dsKeyword; |
54 | if (name=="dsDataType") return dsDataType; | 58 | if (name=="dsDataType") return dsDataType; |
55 | if (name=="dsDecVal") return dsDecVal; | 59 | if (name=="dsDecVal") return dsDecVal; |
56 | if (name=="dsBaseN") return dsBaseN; | 60 | if (name=="dsBaseN") return dsBaseN; |
57 | if (name=="dsFloat") return dsFloat; | 61 | if (name=="dsFloat") return dsFloat; |
58 | if (name=="dsChar") return dsChar; | 62 | if (name=="dsChar") return dsChar; |
59 | if (name=="dsString") return dsString; | 63 | if (name=="dsString") return dsString; |
60 | if (name=="dsComment") return dsComment; | 64 | if (name=="dsComment") return dsComment; |
61 | if (name=="dsOthers") return dsOthers; | 65 | if (name=="dsOthers") return dsOthers; |
62 | 66 | ||
63 | return dsNormal; | 67 | return dsNormal; |
64 | } | 68 | } |
65 | 69 | ||
@@ -99,50 +103,50 @@ const QChar *HlCharDetect::checkHgl(const QChar *str, int len, bool) { | |||
99 | } | 103 | } |
100 | 104 | ||
101 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2) | 105 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2) |
102 | : HlItem(attribute,context) { | 106 | : HlItem(attribute,context) { |
103 | sChar1 = ch1; | 107 | sChar1 = ch1; |
104 | sChar2 = ch2; | 108 | sChar2 = ch2; |
105 | } | 109 | } |
106 | 110 | ||
107 | const QChar *Hl2CharDetect::checkHgl(const QChar *str, int len, bool) { | 111 | const QChar *Hl2CharDetect::checkHgl(const QChar *str, int len, bool) { |
108 | if (str[0] == sChar1 && str[1] == sChar2) return str + 2; | 112 | if (str[0] == sChar1 && str[1] == sChar2) return str + 2; |
109 | return 0L; | 113 | return 0L; |
110 | } | 114 | } |
111 | 115 | ||
112 | HlStringDetect::HlStringDetect(int attribute, int context, const QString &s, bool inSensitive) | 116 | HlStringDetect::HlStringDetect(int attribute, int context, const QString &s, bool inSensitive) |
113 | : HlItem(attribute, context), str(inSensitive ? s.upper():s), _inSensitive(inSensitive) { | 117 | : HlItem(attribute, context), str(inSensitive ? s.upper():s), _inSensitive(inSensitive) { |
114 | } | 118 | } |
115 | 119 | ||
116 | HlStringDetect::~HlStringDetect() { | 120 | HlStringDetect::~HlStringDetect() { |
117 | } | 121 | } |
118 | 122 | ||
119 | const QChar *HlStringDetect::checkHgl(const QChar *s, int len, bool) { | 123 | const QChar *HlStringDetect::checkHgl(const QChar *s, int len, bool) { |
120 | if (!_inSensitive) {if (memcmp(s, str.unicode(), str.length()*sizeof(QChar)) == 0) return s + str.length();} | 124 | if (!_inSensitive) {if (memcmp(s, str.unicode(), str.length()*sizeof(QChar)) == 0) return s + str.length();} |
121 | else | 125 | else |
122 | { | 126 | { |
123 | QString tmp=QString(s,str.length()).upper(); | 127 | QString tmp=QString(s,str.length()).upper(); |
124 | if (tmp==str) return s+str.length(); | 128 | if (tmp==str) return s+str.length(); |
125 | } | 129 | } |
126 | return 0L; | 130 | return 0L; |
127 | } | 131 | } |
128 | 132 | ||
129 | 133 | ||
130 | HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2) | 134 | HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2) |
131 | : HlItem(attribute,context) { | 135 | : HlItem(attribute,context) { |
132 | sChar1 = ch1; | 136 | sChar1 = ch1; |
133 | sChar2 = ch2; | 137 | sChar2 = ch2; |
134 | } | 138 | } |
135 | 139 | ||
136 | const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { | 140 | const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { |
137 | if (*s == sChar1) | 141 | if (*s == sChar1) |
138 | { | 142 | { |
139 | do | 143 | do |
140 | { | 144 | { |
141 | s++; | 145 | s++; |
142 | len--; | 146 | len--; |
143 | if (len == 0) return 0L; | 147 | if (len == 0) return 0L; |
144 | } | 148 | } |
145 | while (*s != sChar2); | 149 | while (*s != sChar2); |
146 | 150 | ||
147 | return s + 1; | 151 | return s + 1; |
148 | } | 152 | } |
@@ -192,91 +196,91 @@ const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b) | |||
192 | len--; | 196 | len--; |
193 | } | 197 | } |
194 | 198 | ||
195 | if (s2 == s) return 0L; | 199 | if (s2 == s) return 0L; |
196 | 200 | ||
197 | QString lookup = QString(s,s2-s); | 201 | QString lookup = QString(s,s2-s); |
198 | 202 | ||
199 | if ( dict.find(lookup) ) return s2; | 203 | if ( dict.find(lookup) ) return s2; |
200 | return 0L; | 204 | return 0L; |
201 | } | 205 | } |
202 | 206 | ||
203 | HlInt::HlInt(int attribute, int context) | 207 | HlInt::HlInt(int attribute, int context) |
204 | : HlItem(attribute,context) { | 208 | : HlItem(attribute,context) { |
205 | } | 209 | } |
206 | 210 | ||
207 | const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { | 211 | const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { |
208 | const QChar *s,*s1; | 212 | const QChar *s,*s1; |
209 | 213 | ||
210 | s = str; | 214 | s = str; |
211 | while (s->isDigit()) s++; | 215 | while (s->isDigit()) s++; |
212 | if (s > str) | 216 | if (s > str) |
213 | { | 217 | { |
214 | if (subItems) | 218 | if (subItems) |
215 | { | 219 | { |
216 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 220 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
217 | { | 221 | { |
218 | s1=it->checkHgl(s, len, false); | 222 | s1=it->checkHgl(s, len, false); |
219 | if (s1) return s1; | 223 | if (s1) return s1; |
220 | } | 224 | } |
221 | } | 225 | } |
222 | return s; | 226 | return s; |
223 | } | 227 | } |
224 | return 0L; | 228 | return 0L; |
225 | } | 229 | } |
226 | 230 | ||
227 | HlFloat::HlFloat(int attribute, int context) | 231 | HlFloat::HlFloat(int attribute, int context) |
228 | : HlItem(attribute,context) { | 232 | : HlItem(attribute,context) { |
229 | } | 233 | } |
230 | 234 | ||
231 | const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { | 235 | const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { |
232 | bool b, p; | 236 | bool b, p; |
233 | const QChar *s1; | 237 | const QChar *s1; |
234 | 238 | ||
235 | b = false; | 239 | b = false; |
236 | while (s->isDigit()){ | 240 | while (s->isDigit()){ |
237 | s++; | 241 | s++; |
238 | b = true; | 242 | b = true; |
239 | } | 243 | } |
240 | if (p = (*s == '.')) { | 244 | if (p = (*s == '.')) { |
241 | s++; | 245 | s++; |
242 | while (s->isDigit()) { | 246 | while (s->isDigit()) { |
243 | s++; | 247 | s++; |
244 | b = true; | 248 | b = true; |
245 | } | 249 | } |
246 | } | 250 | } |
247 | if (!b) return 0L; | 251 | if (!b) return 0L; |
248 | if ((*s&0xdf) == 'E') s++; | 252 | if ((*s&0xdf) == 'E') s++; |
249 | else | 253 | else |
250 | if (!p) return 0L; | 254 | if (!p) return 0L; |
251 | else | 255 | else |
252 | { | 256 | { |
253 | if (subItems) | 257 | if (subItems) |
254 | { | 258 | { |
255 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 259 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
256 | { | 260 | { |
257 | s1=it->checkHgl(s, len, false); | 261 | s1=it->checkHgl(s, len, false); |
258 | if (s1) return s1; | 262 | if (s1) return s1; |
259 | } | 263 | } |
260 | } | 264 | } |
261 | return s; | 265 | return s; |
262 | } | 266 | } |
263 | if ((*s == '-')||(*s =='+')) s++; | 267 | if ((*s == '-')||(*s =='+')) s++; |
264 | b = false; | 268 | b = false; |
265 | while (s->isDigit()) { | 269 | while (s->isDigit()) { |
266 | s++; | 270 | s++; |
267 | b = true; | 271 | b = true; |
268 | } | 272 | } |
269 | if (b) | 273 | if (b) |
270 | { | 274 | { |
271 | if (subItems) | 275 | if (subItems) |
272 | { | 276 | { |
273 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 277 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
274 | { | 278 | { |
275 | s1=it->checkHgl(s, len, false); | 279 | s1=it->checkHgl(s, len, false); |
276 | if (s1) return s1; | 280 | if (s1) return s1; |
277 | } | 281 | } |
278 | } | 282 | } |
279 | return s; | 283 | return s; |
280 | } | 284 | } |
281 | else return 0L; | 285 | else return 0L; |
282 | } | 286 | } |
@@ -324,49 +328,49 @@ const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) { | |||
324 | s = str; | 328 | s = str; |
325 | while (*s >= '0' && *s <= '7') s++; | 329 | while (*s >= '0' && *s <= '7') s++; |
326 | if (s > str) { | 330 | if (s > str) { |
327 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; | 331 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; |
328 | return s; | 332 | return s; |
329 | } | 333 | } |
330 | } | 334 | } |
331 | return 0L; | 335 | return 0L; |
332 | } | 336 | } |
333 | 337 | ||
334 | HlCHex::HlCHex(int attribute, int context) | 338 | HlCHex::HlCHex(int attribute, int context) |
335 | : HlItem(attribute,context) { | 339 | : HlItem(attribute,context) { |
336 | } | 340 | } |
337 | 341 | ||
338 | const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { | 342 | const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { |
339 | const QChar *s=str; | 343 | const QChar *s=str; |
340 | #if 0 | 344 | #if 0 |
341 | int i; | 345 | int i; |
342 | for (i=0;(*s)!='\0';s++,i++); | 346 | for (i=0;(*s)!='\0';s++,i++); |
343 | QString line(str,i); | 347 | QString line(str,i); |
344 | QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis | 348 | QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis |
345 | int pos=rx.search(line,0); | 349 | int pos=rx.search(line,0); |
346 | if(pos > -1) return str+rx.matchedLength(); | 350 | if(pos > -1) return str+rx.matchedLength(); |
347 | else | 351 | else |
348 | return 0L; | 352 | return 0L; |
349 | 353 | ||
350 | #else | 354 | #else |
351 | if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { | 355 | if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { |
352 | str += 2; | 356 | str += 2; |
353 | s = str; | 357 | s = str; |
354 | while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; | 358 | while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; |
355 | if (s > str) { | 359 | if (s > str) { |
356 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; | 360 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; |
357 | return s; | 361 | return s; |
358 | } | 362 | } |
359 | } | 363 | } |
360 | return 0L; | 364 | return 0L; |
361 | #endif | 365 | #endif |
362 | } | 366 | } |
363 | 367 | ||
364 | HlCFloat::HlCFloat(int attribute, int context) | 368 | HlCFloat::HlCFloat(int attribute, int context) |
365 | : HlFloat(attribute,context) { | 369 | : HlFloat(attribute,context) { |
366 | } | 370 | } |
367 | 371 | ||
368 | const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { | 372 | const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { |
369 | 373 | ||
370 | s = HlFloat::checkHgl(s, len, lineStart); | 374 | s = HlFloat::checkHgl(s, len, lineStart); |
371 | if (s && ((*s&0xdf) == 'F' )) s++; | 375 | if (s && ((*s&0xdf) == 'F' )) s++; |
372 | return s; | 376 | return s; |
@@ -379,62 +383,62 @@ HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len | |||
379 | } | 383 | } |
380 | 384 | ||
381 | const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) | 385 | const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) |
382 | { | 386 | { |
383 | if (ustrchr(_charList, _charListLen, *s)) return s +1; | 387 | if (ustrchr(_charList, _charListLen, *s)) return s +1; |
384 | return 0L; | 388 | return 0L; |
385 | } | 389 | } |
386 | 390 | ||
387 | HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) | 391 | HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) |
388 | : HlItem(attribute, context) { | 392 | : HlItem(attribute, context) { |
389 | 393 | ||
390 | handlesLinestart=regexp.startsWith("^"); | 394 | handlesLinestart=regexp.startsWith("^"); |
391 | if(!handlesLinestart) regexp.prepend("^"); | 395 | if(!handlesLinestart) regexp.prepend("^"); |
392 | Expr=new QRegExp3(regexp); | 396 | Expr=new QRegExp3(regexp); |
393 | } | 397 | } |
394 | 398 | ||
395 | const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) | 399 | const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) |
396 | { | 400 | { |
397 | if ((!lineStart) && handlesLinestart) return 0; | 401 | if ((!lineStart) && handlesLinestart) return 0; |
398 | 402 | ||
399 | QString line(s,len); | 403 | QString line(s,len); |
400 | int pos = Expr->search( line, 0 ); | 404 | int pos = Expr->search( line, 0 ); |
401 | if (pos==-1) return 0L; | 405 | if (pos==-1) return 0L; |
402 | else | 406 | else |
403 | return (s+Expr->matchedLength()); | 407 | return (s+Expr->matchedLength()); |
404 | }; | 408 | }; |
405 | 409 | ||
406 | 410 | ||
407 | HlLineContinue::HlLineContinue(int attribute, int context) | 411 | HlLineContinue::HlLineContinue(int attribute, int context) |
408 | : HlItem(attribute,context) { | 412 | : HlItem(attribute,context) { |
409 | } | 413 | } |
410 | 414 | ||
411 | const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { | 415 | const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { |
412 | 416 | ||
413 | if ((s[0].latin1() == '\\') && (len == 1)) | 417 | if ((s[0].latin1() == '\\') && (len == 1)) |
414 | { | 418 | { |
415 | return s + 1; | 419 | return s + 1; |
416 | } | 420 | } |
417 | return 0L; | 421 | return 0L; |
418 | } | 422 | } |
419 | 423 | ||
420 | 424 | ||
421 | HlCStringChar::HlCStringChar(int attribute, int context) | 425 | HlCStringChar::HlCStringChar(int attribute, int context) |
422 | : HlItem(attribute,context) { | 426 | : HlItem(attribute,context) { |
423 | } | 427 | } |
424 | 428 | ||
425 | //checks for hex and oct (for example \x1b or \033) | 429 | //checks for hex and oct (for example \x1b or \033) |
426 | const QChar *checkCharHexOct(const QChar *str) { | 430 | const QChar *checkCharHexOct(const QChar *str) { |
427 | const QChar *s; | 431 | const QChar *s; |
428 | s=str; | 432 | s=str; |
429 | int n; | 433 | int n; |
430 | if (*s == 'x') { | 434 | if (*s == 'x') { |
431 | n = 0; | 435 | n = 0; |
432 | do { | 436 | do { |
433 | s++; | 437 | s++; |
434 | n *= 16; | 438 | n *= 16; |
435 | if (s->isDigit()) n += *s - '0'; | 439 | if (s->isDigit()) n += *s - '0'; |
436 | else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; | 440 | else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; |
437 | // else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; | 441 | // else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; |
438 | else break; | 442 | else break; |
439 | if (n >= 256) return 0L; | 443 | if (n >= 256) return 0L; |
440 | } while (true); | 444 | } while (true); |
@@ -600,49 +604,49 @@ int Highlight::doHighlight(int ctxNum, TextLine *textLine) | |||
600 | QChar lastChar = ' '; | 604 | QChar lastChar = ' '; |
601 | 605 | ||
602 | // first char | 606 | // first char |
603 | const QChar *str = textLine->getText(); | 607 | const QChar *str = textLine->getText(); |
604 | 608 | ||
605 | // non space char - index of that char | 609 | // non space char - index of that char |
606 | const QChar *s1 = textLine->firstNonSpace(); | 610 | const QChar *s1 = textLine->firstNonSpace(); |
607 | uint z = textLine->firstChar(); | 611 | uint z = textLine->firstChar(); |
608 | 612 | ||
609 | // length of textline | 613 | // length of textline |
610 | uint len = textLine->length(); | 614 | uint len = textLine->length(); |
611 | 615 | ||
612 | bool found = false; | 616 | bool found = false; |
613 | while (z < len) | 617 | while (z < len) |
614 | { | 618 | { |
615 | found = false; | 619 | found = false; |
616 | 620 | ||
617 | for (item = context->items.first(); item != 0L; item = context->items.next()) | 621 | for (item = context->items.first(); item != 0L; item = context->items.next()) |
618 | { | 622 | { |
619 | if (item->startEnable(lastChar)) | 623 | if (item->startEnable(lastChar)) |
620 | { | 624 | { |
621 | s2 = item->checkHgl(s1, len-z, z==0); | 625 | s2 = item->checkHgl(s1, len-z, z==0); |
622 | if (s2 > s1) | 626 | if (s2 > s1) |
623 | { | 627 | { |
624 | qDebug("An item has been detected"); | 628 | odebug << "An item has been detected" << oendl; |
625 | textLine->setAttribs(item->attr,s1 - str,s2 - str); | 629 | textLine->setAttribs(item->attr,s1 - str,s2 - str); |
626 | ctxNum = item->ctx; | 630 | ctxNum = item->ctx; |
627 | context = contextList[ctxNum]; | 631 | context = contextList[ctxNum]; |
628 | z = z + s2 - s1 - 1; | 632 | z = z + s2 - s1 - 1; |
629 | s1 = s2 - 1; | 633 | s1 = s2 - 1; |
630 | found = true; | 634 | found = true; |
631 | break; | 635 | break; |
632 | } | 636 | } |
633 | } | 637 | } |
634 | } | 638 | } |
635 | 639 | ||
636 | // nothing found: set attribute of one char | 640 | // nothing found: set attribute of one char |
637 | if (!found) | 641 | if (!found) |
638 | textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); | 642 | textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); |
639 | 643 | ||
640 | lastChar = *s1; | 644 | lastChar = *s1; |
641 | s1++; | 645 | s1++; |
642 | z++; | 646 | z++; |
643 | } | 647 | } |
644 | 648 | ||
645 | //set "end of line"-properties | 649 | //set "end of line"-properties |
646 | textLine->setAttr(context->attr); | 650 | textLine->setAttr(context->attr); |
647 | 651 | ||
648 | //return new context | 652 | //return new context |
@@ -832,78 +836,78 @@ void Highlight::done() | |||
832 | { | 836 | { |
833 | if (noHl) | 837 | if (noHl) |
834 | return; | 838 | return; |
835 | 839 | ||
836 | for (int z = 0; z < nContexts; z++) delete contextList[z]; | 840 | for (int z = 0; z < nContexts; z++) delete contextList[z]; |
837 | } | 841 | } |
838 | 842 | ||
839 | 843 | ||
840 | /******************************************************************************************* | 844 | /******************************************************************************************* |
841 | Highlight - createItemData | 845 | Highlight - createItemData |
842 | This function reads the itemData entries from the config file, which specifies the | 846 | This function reads the itemData entries from the config file, which specifies the |
843 | default attribute styles for matched items/contexts. | 847 | default attribute styles for matched items/contexts. |
844 | 848 | ||
845 | * input: none | 849 | * input: none |
846 | ************* | 850 | ************* |
847 | * output: ItemDataList &list :A reference to the internal | 851 | * output: ItemDataList &list :A reference to the internal |
848 | list containing the parsed | 852 | list containing the parsed |
849 | default config | 853 | default config |
850 | ************* | 854 | ************* |
851 | * return value: none | 855 | * return value: none |
852 | *******************************************************************************************/ | 856 | *******************************************************************************************/ |
853 | 857 | ||
854 | void Highlight::createItemData(ItemDataList &list) | 858 | void Highlight::createItemData(ItemDataList &list) |
855 | { | 859 | { |
856 | qDebug("Highlight::createItemData"); | 860 | odebug << "Highlight::createItemData" << oendl; |
857 | 861 | ||
858 | // If no highlighting is selected we need only one default. | 862 | // If no highlighting is selected we need only one default. |
859 | if (noHl) | 863 | if (noHl) |
860 | { | 864 | { |
861 | list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal)); | 865 | list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal)); |
862 | return; | 866 | return; |
863 | } | 867 | } |
864 | 868 | ||
865 | QString color; | 869 | QString color; |
866 | QString selColor; | 870 | QString selColor; |
867 | QString bold; | 871 | QString bold; |
868 | QString italic; | 872 | QString italic; |
869 | 873 | ||
870 | // If the internal list isn't already available read the config file | 874 | // If the internal list isn't already available read the config file |
871 | if (internalIDList.count()==0) | 875 | if (internalIDList.count()==0) |
872 | { | 876 | { |
873 | //if all references to the list are destried the contents will also be deleted | 877 | //if all references to the list are destried the contents will also be deleted |
874 | internalIDList.setAutoDelete(true); | 878 | internalIDList.setAutoDelete(true); |
875 | syntaxContextData *data; | 879 | syntaxContextData *data; |
876 | 880 | ||
877 | qDebug("Trying to read itemData section"); | 881 | odebug << "Trying to read itemData section" << oendl; |
878 | 882 | ||
879 | //Tell the syntax document class which file we want to parse and which data group | 883 | //Tell the syntax document class which file we want to parse and which data group |
880 | HlManager::self()->syntax->setIdentifier(identifier); | 884 | HlManager::self()->syntax->setIdentifier(identifier); |
881 | data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); | 885 | data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); |
882 | //begin with the real parsing | 886 | //begin with the real parsing |
883 | while (HlManager::self()->syntax->nextGroup(data)) | 887 | while (HlManager::self()->syntax->nextGroup(data)) |
884 | { | 888 | { |
885 | qDebug("Setting up one itemData element"); | 889 | odebug << "Setting up one itemData element" << oendl; |
886 | // read all attributes | 890 | // read all attributes |
887 | color=HlManager::self()->syntax->groupData(data,QString("color")); | 891 | color=HlManager::self()->syntax->groupData(data,QString("color")); |
888 | selColor=HlManager::self()->syntax->groupData(data,QString("selColor")); | 892 | selColor=HlManager::self()->syntax->groupData(data,QString("selColor")); |
889 | bold=HlManager::self()->syntax->groupData(data,QString("bold")); | 893 | bold=HlManager::self()->syntax->groupData(data,QString("bold")); |
890 | italic=HlManager::self()->syntax->groupData(data,QString("italic")); | 894 | italic=HlManager::self()->syntax->groupData(data,QString("italic")); |
891 | //check if the user overrides something | 895 | //check if the user overrides something |
892 | if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty())) | 896 | if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty())) |
893 | { | 897 | { |
894 | //create a user defined style | 898 | //create a user defined style |
895 | internalIDList.append(new ItemData( | 899 | internalIDList.append(new ItemData( |
896 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), | 900 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), |
897 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))), | 901 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))), |
898 | QColor(color),QColor(selColor),(bold=="true") || (bold=="1"), (italic=="true") || (italic=="1") | 902 | QColor(color),QColor(selColor),(bold=="true") || (bold=="1"), (italic=="true") || (italic=="1") |
899 | )); | 903 | )); |
900 | } | 904 | } |
901 | else | 905 | else |
902 | { | 906 | { |
903 | //assign a default style | 907 | //assign a default style |
904 | internalIDList.append(new ItemData( | 908 | internalIDList.append(new ItemData( |
905 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), | 909 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), |
906 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))))); | 910 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))))); |
907 | 911 | ||
908 | } | 912 | } |
909 | } | 913 | } |
@@ -912,54 +916,54 @@ void Highlight::createItemData(ItemDataList &list) | |||
912 | } | 916 | } |
913 | 917 | ||
914 | //set the ouput reference | 918 | //set the ouput reference |
915 | list=internalIDList; | 919 | list=internalIDList; |
916 | } | 920 | } |
917 | 921 | ||
918 | 922 | ||
919 | /******************************************************************************************* | 923 | /******************************************************************************************* |
920 | Highlight - lookupAttrName | 924 | Highlight - lookupAttrName |
921 | This function is a helper for makeContextList and createHlItem. It looks the given | 925 | This function is a helper for makeContextList and createHlItem. It looks the given |
922 | attribute name in the itemData list up and returns it's index | 926 | attribute name in the itemData list up and returns it's index |
923 | 927 | ||
924 | * input: QString &name :the attribute name to lookup | 928 | * input: QString &name :the attribute name to lookup |
925 | * ItemDataList &iDl :the list containing all | 929 | * ItemDataList &iDl :the list containing all |
926 | * available attributes | 930 | * available attributes |
927 | ************* | 931 | ************* |
928 | * output: none | 932 | * output: none |
929 | ************* | 933 | ************* |
930 | * return value: int :The index of the attribute | 934 | * return value: int :The index of the attribute |
931 | * or 0 | 935 | * or 0 |
932 | *******************************************************************************************/ | 936 | *******************************************************************************************/ |
933 | 937 | ||
934 | int Highlight::lookupAttrName(const QString& name, ItemDataList &iDl) | 938 | int Highlight::lookupAttrName(const QString& name, ItemDataList &iDl) |
935 | { | 939 | { |
936 | for (int i=0;i<iDl.count();i++) | 940 | for (int i=0;i<iDl.count();i++) |
937 | { | 941 | { |
938 | if (iDl.at(i)->name==name) return i; | 942 | if (iDl.at(i)->name==name) return i; |
939 | } | 943 | } |
940 | kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl; | 944 | kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl; |
941 | return 0; | 945 | return 0; |
942 | } | 946 | } |
943 | 947 | ||
944 | 948 | ||
945 | /******************************************************************************************* | 949 | /******************************************************************************************* |
946 | Highlight - createHlItem | 950 | Highlight - createHlItem |
947 | This function is a helper for makeContextList. It parses the xml file for | 951 | This function is a helper for makeContextList. It parses the xml file for |
948 | information, how single or multi line comments are marked | 952 | information, how single or multi line comments are marked |
949 | 953 | ||
950 | * input: syntaxContextData *data : Data about the item read from | 954 | * input: syntaxContextData *data : Data about the item read from |
951 | * the xml file | 955 | * the xml file |
952 | * ItemDataList &iDl : List of all available itemData | 956 | * ItemDataList &iDl : List of all available itemData |
953 | * entries. Needed for attribute | 957 | * entries. Needed for attribute |
954 | * name->index translation | 958 | * name->index translation |
955 | ************* | 959 | ************* |
956 | * output: none | 960 | * output: none |
957 | ************* | 961 | ************* |
958 | * return value: HlItem * : Pointer to the newly created item | 962 | * return value: HlItem * : Pointer to the newly created item |
959 | * object | 963 | * object |
960 | *******************************************************************************************/ | 964 | *******************************************************************************************/ |
961 | 965 | ||
962 | HlItem *Highlight::createHlItem(syntaxContextData *data, ItemDataList &iDl) | 966 | HlItem *Highlight::createHlItem(syntaxContextData *data, ItemDataList &iDl) |
963 | { | 967 | { |
964 | // No highlighting -> exit | 968 | // No highlighting -> exit |
965 | if (noHl) | 969 | if (noHl) |
@@ -1056,105 +1060,105 @@ bool Highlight::isInWord(QChar c) | |||
1056 | This function is a helper for makeContextList. It parses the xml file for | 1060 | This function is a helper for makeContextList. It parses the xml file for |
1057 | information, how single or multi line comments are marked | 1061 | information, how single or multi line comments are marked |
1058 | 1062 | ||
1059 | * input: none | 1063 | * input: none |
1060 | ************* | 1064 | ************* |
1061 | * output: none | 1065 | * output: none |
1062 | ************* | 1066 | ************* |
1063 | * return value: none | 1067 | * return value: none |
1064 | *******************************************************************************************/ | 1068 | *******************************************************************************************/ |
1065 | 1069 | ||
1066 | void Highlight::readCommentConfig() | 1070 | void Highlight::readCommentConfig() |
1067 | { | 1071 | { |
1068 | 1072 | ||
1069 | cslStart = ""; | 1073 | cslStart = ""; |
1070 | HlManager::self()->syntax->setIdentifier(identifier); | 1074 | HlManager::self()->syntax->setIdentifier(identifier); |
1071 | 1075 | ||
1072 | syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment"); | 1076 | syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment"); |
1073 | if (data) | 1077 | if (data) |
1074 | { | 1078 | { |
1075 | // kdDebug(13010)<<"COMMENT DATA FOUND"<<endl; | 1079 | // kdDebug(13010)<<"COMMENT DATA FOUND"<<endl; |
1076 | while (HlManager::self()->syntax->nextGroup(data)) | 1080 | while (HlManager::self()->syntax->nextGroup(data)) |
1077 | { | 1081 | { |
1078 | 1082 | ||
1079 | if (HlManager::self()->syntax->groupData(data,"name")=="singleLine") | 1083 | if (HlManager::self()->syntax->groupData(data,"name")=="singleLine") |
1080 | cslStart=HlManager::self()->syntax->groupData(data,"start"); | 1084 | cslStart=HlManager::self()->syntax->groupData(data,"start"); |
1081 | if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") | 1085 | if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") |
1082 | { | 1086 | { |
1083 | cmlStart=HlManager::self()->syntax->groupData(data,"start"); | 1087 | cmlStart=HlManager::self()->syntax->groupData(data,"start"); |
1084 | cmlEnd=HlManager::self()->syntax->groupData(data,"end"); | 1088 | cmlEnd=HlManager::self()->syntax->groupData(data,"end"); |
1085 | } | 1089 | } |
1086 | } | 1090 | } |
1087 | HlManager::self()->syntax->freeGroupInfo(data); | 1091 | HlManager::self()->syntax->freeGroupInfo(data); |
1088 | } | 1092 | } |
1089 | 1093 | ||
1090 | } | 1094 | } |
1091 | 1095 | ||
1092 | /******************************************************************************************* | 1096 | /******************************************************************************************* |
1093 | Highlight - readGlobalKeyWordConfig | 1097 | Highlight - readGlobalKeyWordConfig |
1094 | This function is a helper for makeContextList. It parses the xml file for | 1098 | This function is a helper for makeContextList. It parses the xml file for |
1095 | information, if keywords should be treated case(in)sensitive and creates the keyword | 1099 | information, if keywords should be treated case(in)sensitive and creates the keyword |
1096 | delimiter list. Which is the default list, without any given weak deliminiators | 1100 | delimiter list. Which is the default list, without any given weak deliminiators |
1097 | 1101 | ||
1098 | * input: none | 1102 | * input: none |
1099 | ************* | 1103 | ************* |
1100 | * output: none | 1104 | * output: none |
1101 | ************* | 1105 | ************* |
1102 | * return value: none | 1106 | * return value: none |
1103 | *******************************************************************************************/ | 1107 | *******************************************************************************************/ |
1104 | 1108 | ||
1105 | 1109 | ||
1106 | void Highlight::readGlobalKeywordConfig() | 1110 | void Highlight::readGlobalKeywordConfig() |
1107 | { | 1111 | { |
1108 | // Tell the syntax document class which file we want to parse | 1112 | // Tell the syntax document class which file we want to parse |
1109 | HlManager::self()->syntax->setIdentifier(identifier); | 1113 | HlManager::self()->syntax->setIdentifier(identifier); |
1110 | 1114 | ||
1111 | // Get the keywords config entry | 1115 | // Get the keywords config entry |
1112 | syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords"); | 1116 | syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords"); |
1113 | if (data) | 1117 | if (data) |
1114 | { | 1118 | { |
1115 | kdDebug(13010)<<"Found global keyword config"<<endl; | 1119 | kdDebug(13010)<<"Found global keyword config"<<endl; |
1116 | 1120 | ||
1117 | if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0") | 1121 | if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0") |
1118 | casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} | 1122 | casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} |
1119 | //get the weak deliminators | 1123 | //get the weak deliminators |
1120 | weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator"))); | 1124 | weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator"))); |
1121 | 1125 | ||
1122 | // remove any weakDelimitars (if any) from the default list and store this list. | 1126 | // remove any weakDelimitars (if any) from the default list and store this list. |
1123 | int f; | 1127 | int f; |
1124 | for (int s=0; s < weakDeliminator.length(); s++) | 1128 | for (int s=0; s < weakDeliminator.length(); s++) |
1125 | { | 1129 | { |
1126 | f = 0; | 1130 | f = 0; |
1127 | f = deliminator.find (weakDeliminator[s]); | 1131 | f = deliminator.find (weakDeliminator[s]); |
1128 | 1132 | ||
1129 | if (f > -1) | 1133 | if (f > -1) |
1130 | deliminator.remove (f, 1); | 1134 | deliminator.remove (f, 1); |
1131 | } | 1135 | } |
1132 | 1136 | ||
1133 | deliminatorChars = deliminator.unicode(); | 1137 | deliminatorChars = deliminator.unicode(); |
1134 | deliminatorLen = deliminator.length(); | 1138 | deliminatorLen = deliminator.length(); |
1135 | 1139 | ||
1136 | HlManager::self()->syntax->freeGroupInfo(data); | 1140 | HlManager::self()->syntax->freeGroupInfo(data); |
1137 | } | 1141 | } |
1138 | else | 1142 | else |
1139 | { | 1143 | { |
1140 | //Default values | 1144 | //Default values |
1141 | casesensitive=true; | 1145 | casesensitive=true; |
1142 | weakDeliminator=QString(""); | 1146 | weakDeliminator=QString(""); |
1143 | } | 1147 | } |
1144 | 1148 | ||
1145 | } | 1149 | } |
1146 | 1150 | ||
1147 | /******************************************************************************************* | 1151 | /******************************************************************************************* |
1148 | Highlight - makeContextList | 1152 | Highlight - makeContextList |
1149 | That's the most important initialization function for each highlighting. It's called | 1153 | That's the most important initialization function for each highlighting. It's called |
1150 | each time a document gets a highlighting style assigned. parses the xml file and | 1154 | each time a document gets a highlighting style assigned. parses the xml file and |
1151 | creates a corresponding internal structure | 1155 | creates a corresponding internal structure |
1152 | 1156 | ||
1153 | * input: none | 1157 | * input: none |
1154 | ************* | 1158 | ************* |
1155 | * output: none | 1159 | * output: none |
1156 | ************* | 1160 | ************* |
1157 | * return value: none | 1161 | * return value: none |
1158 | *******************************************************************************************/ | 1162 | *******************************************************************************************/ |
1159 | 1163 | ||
1160 | 1164 | ||
@@ -1183,67 +1187,67 @@ void Highlight::makeContextList() | |||
1183 | if (data) | 1187 | if (data) |
1184 | { | 1188 | { |
1185 | while (HlManager::self()->syntax->nextGroup(data)) | 1189 | while (HlManager::self()->syntax->nextGroup(data)) |
1186 | { | 1190 | { |
1187 | 1191 | ||
1188 | // BEGIN - Translation of the attribute parameter | 1192 | // BEGIN - Translation of the attribute parameter |
1189 | QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace(); | 1193 | QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace(); |
1190 | int attr; | 1194 | int attr; |
1191 | if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) | 1195 | if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) |
1192 | attr=tmpAttr.toInt(); | 1196 | attr=tmpAttr.toInt(); |
1193 | else | 1197 | else |
1194 | attr=lookupAttrName(tmpAttr,iDl); | 1198 | attr=lookupAttrName(tmpAttr,iDl); |
1195 | // END - Translation of the attribute parameter | 1199 | // END - Translation of the attribute parameter |
1196 | 1200 | ||
1197 | contextList[i]=new HlContext( | 1201 | contextList[i]=new HlContext( |
1198 | attr, | 1202 | attr, |
1199 | (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(), | 1203 | (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(), |
1200 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1: | 1204 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1: |
1201 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt()); | 1205 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt()); |
1202 | 1206 | ||
1203 | 1207 | ||
1204 | //Let's create all items for the context | 1208 | //Let's create all items for the context |
1205 | while (HlManager::self()->syntax->nextItem(data)) | 1209 | while (HlManager::self()->syntax->nextItem(data)) |
1206 | { | 1210 | { |
1207 | // kdDebug(13010)<< "In make Contextlist: Item:"<<endl; | 1211 | // kdDebug(13010)<< "In make Contextlist: Item:"<<endl; |
1208 | c=createHlItem(data,iDl); | 1212 | c=createHlItem(data,iDl); |
1209 | if (c) | 1213 | if (c) |
1210 | { | 1214 | { |
1211 | contextList[i]->items.append(c); | 1215 | contextList[i]->items.append(c); |
1212 | 1216 | ||
1213 | // Not supported completely atm and only one level. Subitems.(all have to be matched to at once) | 1217 | // Not supported completely atm and only one level. Subitems.(all have to be matched to at once) |
1214 | datasub=HlManager::self()->syntax->getSubItems(data); | 1218 | datasub=HlManager::self()->syntax->getSubItems(data); |
1215 | bool tmpbool; | 1219 | bool tmpbool; |
1216 | if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) | 1220 | if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) |
1217 | { | 1221 | { |
1218 | c->subItems=new QList<HlItem>; | 1222 | c->subItems=new QList<HlItem>; |
1219 | for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) | 1223 | for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) |
1220 | c->subItems->append(createHlItem(datasub,iDl)); | 1224 | c->subItems->append(createHlItem(datasub,iDl)); |
1221 | } | 1225 | } |
1222 | HlManager::self()->syntax->freeGroupInfo(datasub); | 1226 | HlManager::self()->syntax->freeGroupInfo(datasub); |
1223 | // end of sublevel | 1227 | // end of sublevel |
1224 | } | 1228 | } |
1225 | // kdDebug(13010)<<"Last line in loop"<<endl; | 1229 | // kdDebug(13010)<<"Last line in loop"<<endl; |
1226 | } | 1230 | } |
1227 | i++; | 1231 | i++; |
1228 | } | 1232 | } |
1229 | } | 1233 | } |
1230 | 1234 | ||
1231 | HlManager::self()->syntax->freeGroupInfo(data); | 1235 | HlManager::self()->syntax->freeGroupInfo(data); |
1232 | 1236 | ||
1233 | 1237 | ||
1234 | } | 1238 | } |
1235 | 1239 | ||
1236 | HlManager::HlManager() : QObject(0L) | 1240 | HlManager::HlManager() : QObject(0L) |
1237 | { | 1241 | { |
1238 | syntax = new SyntaxDocument(); | 1242 | syntax = new SyntaxDocument(); |
1239 | SyntaxModeList modeList = syntax->modeList(); | 1243 | SyntaxModeList modeList = syntax->modeList(); |
1240 | 1244 | ||
1241 | hlList.setAutoDelete(true); | 1245 | hlList.setAutoDelete(true); |
1242 | hlList.append(new Highlight(0)); | 1246 | hlList.append(new Highlight(0)); |
1243 | 1247 | ||
1244 | uint i=0; | 1248 | uint i=0; |
1245 | while (i < modeList.count()) | 1249 | while (i < modeList.count()) |
1246 | { | 1250 | { |
1247 | hlList.append(new Highlight(modeList.at(i))); | 1251 | hlList.append(new Highlight(modeList.at(i))); |
1248 | i++; | 1252 | i++; |
1249 | } | 1253 | } |
@@ -1291,58 +1295,58 @@ int HlManager::wildcardFind(const QString &fileName) { | |||
1291 | for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) { | 1295 | for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) { |
1292 | p1 = 0; | 1296 | p1 = 0; |
1293 | w = highlight->getWildcards(); | 1297 | w = highlight->getWildcards(); |
1294 | while (p1 < (int) w.length()) { | 1298 | while (p1 < (int) w.length()) { |
1295 | p2 = w.find(';',p1); | 1299 | p2 = w.find(';',p1); |
1296 | if (p2 == -1) p2 = w.length(); | 1300 | if (p2 == -1) p2 = w.length(); |
1297 | if (p1 < p2) { | 1301 | if (p1 < p2) { |
1298 | QRegExp regExp(w.mid(p1,p2 - p1),true,true); | 1302 | QRegExp regExp(w.mid(p1,p2 - p1),true,true); |
1299 | if (regExp.match(fileName) == 0) return hlList.at(); | 1303 | if (regExp.match(fileName) == 0) return hlList.at(); |
1300 | } | 1304 | } |
1301 | p1 = p2 + 1; | 1305 | p1 = p2 + 1; |
1302 | } | 1306 | } |
1303 | } | 1307 | } |
1304 | return -1; | 1308 | return -1; |
1305 | } | 1309 | } |
1306 | 1310 | ||
1307 | 1311 | ||
1308 | int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { | 1312 | int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { |
1309 | ItemStyleList defaultStyleList; | 1313 | ItemStyleList defaultStyleList; |
1310 | ItemStyle *defaultStyle; | 1314 | ItemStyle *defaultStyle; |
1311 | ItemDataList itemDataList; | 1315 | ItemDataList itemDataList; |
1312 | ItemData *itemData; | 1316 | ItemData *itemData; |
1313 | int nAttribs, z; | 1317 | int nAttribs, z; |
1314 | 1318 | ||
1315 | qDebug("HlManager::makeAttribs"); | 1319 | odebug << "HlManager::makeAttribs" << oendl; |
1316 | 1320 | ||
1317 | defaultStyleList.setAutoDelete(true); | 1321 | defaultStyleList.setAutoDelete(true); |
1318 | getDefaults(defaultStyleList); | 1322 | getDefaults(defaultStyleList); |
1319 | 1323 | ||
1320 | // itemDataList.setAutoDelete(true); | 1324 | // itemDataList.setAutoDelete(true); |
1321 | highlight->getItemDataList(itemDataList); | 1325 | highlight->getItemDataList(itemDataList); |
1322 | nAttribs = itemDataList.count(); | 1326 | nAttribs = itemDataList.count(); |
1323 | for (z = 0; z < nAttribs; z++) { | 1327 | for (z = 0; z < nAttribs; z++) { |
1324 | qDebug("HlManager::makeAttribs: createing one attribute definition"); | 1328 | odebug << "HlManager::makeAttribs: createing one attribute definition" << oendl; |
1325 | itemData = itemDataList.at(z); | 1329 | itemData = itemDataList.at(z); |
1326 | if (itemData->defStyle) { | 1330 | if (itemData->defStyle) { |
1327 | // default style | 1331 | // default style |
1328 | defaultStyle = defaultStyleList.at(itemData->defStyleNum); | 1332 | defaultStyle = defaultStyleList.at(itemData->defStyleNum); |
1329 | a[z].col = defaultStyle->col; | 1333 | a[z].col = defaultStyle->col; |
1330 | a[z].selCol = defaultStyle->selCol; | 1334 | a[z].selCol = defaultStyle->selCol; |
1331 | a[z].bold = defaultStyle->bold; | 1335 | a[z].bold = defaultStyle->bold; |
1332 | a[z].italic = defaultStyle->italic; | 1336 | a[z].italic = defaultStyle->italic; |
1333 | } else { | 1337 | } else { |
1334 | // custom style | 1338 | // custom style |
1335 | a[z].col = itemData->col; | 1339 | a[z].col = itemData->col; |
1336 | a[z].selCol = itemData->selCol; | 1340 | a[z].selCol = itemData->selCol; |
1337 | a[z].bold = itemData->bold; | 1341 | a[z].bold = itemData->bold; |
1338 | a[z].italic = itemData->italic; | 1342 | a[z].italic = itemData->italic; |
1339 | } | 1343 | } |
1340 | } | 1344 | } |
1341 | 1345 | ||
1342 | for (; z < maxAttribs; z++) { | 1346 | for (; z < maxAttribs; z++) { |
1343 | a[z].col = black; | 1347 | a[z].col = black; |
1344 | a[z].selCol = black; | 1348 | a[z].selCol = black; |
1345 | a[z].bold = defaultStyle->bold; | 1349 | a[z].bold = defaultStyle->bold; |
1346 | a[z].italic = defaultStyle->italic; | 1350 | a[z].italic = defaultStyle->italic; |
1347 | } | 1351 | } |
1348 | return nAttribs; | 1352 | return nAttribs; |
@@ -1394,49 +1398,49 @@ void HlManager::getDefaults(ItemStyleList &list) { | |||
1394 | list.append(new ItemStyle(darkGreen,green,false,false)); //others | 1398 | list.append(new ItemStyle(darkGreen,green,false,false)); //others |
1395 | 1399 | ||
1396 | #warning fixme | 1400 | #warning fixme |
1397 | /* | 1401 | /* |
1398 | config = KateFactory::instance()->config(); | 1402 | config = KateFactory::instance()->config(); |
1399 | config->setGroup("Default Item Styles"); | 1403 | config->setGroup("Default Item Styles"); |
1400 | for (z = 0; z < defaultStyles(); z++) { | 1404 | for (z = 0; z < defaultStyles(); z++) { |
1401 | i = list.at(z); | 1405 | i = list.at(z); |
1402 | s = config->readEntry(defaultStyleName(z)); | 1406 | s = config->readEntry(defaultStyleName(z)); |
1403 | if (!s.isEmpty()) { | 1407 | if (!s.isEmpty()) { |
1404 | sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic); | 1408 | sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic); |
1405 | i->col.setRgb(col); | 1409 | i->col.setRgb(col); |
1406 | i->selCol.setRgb(selCol); | 1410 | i->selCol.setRgb(selCol); |
1407 | } | 1411 | } |
1408 | } | 1412 | } |
1409 | */ | 1413 | */ |
1410 | } | 1414 | } |
1411 | 1415 | ||
1412 | void HlManager::setDefaults(ItemStyleList &list) { | 1416 | void HlManager::setDefaults(ItemStyleList &list) { |
1413 | KateConfig *config; | 1417 | KateConfig *config; |
1414 | int z; | 1418 | int z; |
1415 | ItemStyle *i; | 1419 | ItemStyle *i; |
1416 | char s[64]; | 1420 | char s[64]; |
1417 | #warning fixme | 1421 | #warning fixme |
1418 | /* | 1422 | /* |
1419 | config = KateFactory::instance()->config(); | 1423 | config = KateFactory::instance()->config(); |
1420 | config->setGroup("Default Item Styles"); | 1424 | config->setGroup("Default Item Styles"); |
1421 | for (z = 0; z < defaultStyles(); z++) { | 1425 | for (z = 0; z < defaultStyles(); z++) { |
1422 | i = list.at(z); | 1426 | i = list.at(z); |
1423 | sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic); | 1427 | sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic); |
1424 | config->writeEntry(defaultStyleName(z),s); | 1428 | config->writeEntry(defaultStyleName(z),s); |
1425 | } | 1429 | } |
1426 | */ | 1430 | */ |
1427 | emit changed(); | 1431 | emit changed(); |
1428 | } | 1432 | } |
1429 | 1433 | ||
1430 | 1434 | ||
1431 | int HlManager::highlights() { | 1435 | int HlManager::highlights() { |
1432 | return (int) hlList.count(); | 1436 | return (int) hlList.count(); |
1433 | } | 1437 | } |
1434 | 1438 | ||
1435 | QString HlManager::hlName(int n) { | 1439 | QString HlManager::hlName(int n) { |
1436 | return hlList.at(n)->iName; | 1440 | return hlList.at(n)->iName; |
1437 | } | 1441 | } |
1438 | 1442 | ||
1439 | QString HlManager::hlSection(int n) { | 1443 | QString HlManager::hlSection(int n) { |
1440 | return hlList.at(n)->iSection; | 1444 | return hlList.at(n)->iSection; |
1441 | } | 1445 | } |
1442 | 1446 | ||
diff --git a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp index 6059e9b..9fa4452 100644 --- a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp | |||
@@ -1,117 +1,122 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katesyntaxdocument.cpp - description | 2 | katesyntaxdocument.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Sat 31 March 2001 | 4 | begin : Sat 31 March 2001 |
5 | copyright : (C) 2001,2002 by Joseph Wenninger | 5 | copyright : (C) 2001,2002 by Joseph Wenninger |
6 | email : jowenn@kde.org | 6 | email : jowenn@kde.org |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include "katesyntaxdocument.h" | 18 | #include "katesyntaxdocument.h" |
19 | #include <kateconfig.h> | 19 | #include "kateconfig.h" |
20 | #include "kdebug.h" | ||
21 | #include "kstddirs.h" | ||
22 | #include "klocale.h" | ||
23 | #include "kmessagebox.h" | ||
24 | #include "kglobal.h" | ||
25 | |||
26 | /* OPIE */ | ||
27 | #include <opie2/odebug.h> | ||
28 | #include <qpe/qpeapplication.h> | ||
29 | |||
30 | /* QT */ | ||
20 | #include <qfile.h> | 31 | #include <qfile.h> |
21 | #include <kdebug.h> | ||
22 | #include <kstddirs.h> | ||
23 | #include <klocale.h> | ||
24 | #include <kmessagebox.h> | ||
25 | #include <qstringlist.h> | 32 | #include <qstringlist.h> |
26 | #include <kglobal.h> | ||
27 | #include <qpe/qpeapplication.h> | ||
28 | #include <qdir.h> | 33 | #include <qdir.h> |
29 | 34 | ||
30 | SyntaxDocument::SyntaxDocument() | 35 | SyntaxDocument::SyntaxDocument() |
31 | { | 36 | { |
32 | m_root=0; | 37 | m_root=0; |
33 | currentFile=""; | 38 | currentFile=""; |
34 | setupModeList(); | 39 | setupModeList(); |
35 | } | 40 | } |
36 | 41 | ||
37 | void SyntaxDocument::setIdentifier(const QString& identifier) | 42 | void SyntaxDocument::setIdentifier(const QString& identifier) |
38 | { | 43 | { |
39 | #warning FIXME delete m_root; | 44 | #warning FIXME delete m_root; |
40 | m_root=Opie::Core::XMLElement::load(identifier); | 45 | m_root=Opie::Core::XMLElement::load(identifier); |
41 | if (!m_root) KMessageBox::error( 0L, i18n("Can't open %1").arg(identifier) ); | 46 | if (!m_root) KMessageBox::error( 0L, i18n("Can't open %1").arg(identifier) ); |
42 | 47 | ||
43 | } | 48 | } |
44 | 49 | ||
45 | SyntaxDocument::~SyntaxDocument() | 50 | SyntaxDocument::~SyntaxDocument() |
46 | { | 51 | { |
47 | } | 52 | } |
48 | 53 | ||
49 | void SyntaxDocument::setupModeList(bool force) | 54 | void SyntaxDocument::setupModeList(bool force) |
50 | { | 55 | { |
51 | 56 | ||
52 | if (myModeList.count() > 0) return; | 57 | if (myModeList.count() > 0) return; |
53 | 58 | ||
54 | KateConfig *config=KGlobal::config(); | 59 | KateConfig *config=KGlobal::config(); |
55 | KStandardDirs *dirs = KGlobal::dirs(); | 60 | KStandardDirs *dirs = KGlobal::dirs(); |
56 | 61 | ||
57 | // QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true); | 62 | // QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true); |
58 | QString path=QPEApplication::qpeDir() +"share/tinykate/syntax/"; | 63 | QString path=QPEApplication::qpeDir() +"share/tinykate/syntax/"; |
59 | 64 | ||
60 | QDir dir(path); | 65 | QDir dir(path); |
61 | QStringList list=dir.entryList("*.xml"); | 66 | QStringList list=dir.entryList("*.xml"); |
62 | 67 | ||
63 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 68 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
64 | { | 69 | { |
65 | QString Group="Highlighting_Cache"+path+*it; | 70 | QString Group="Highlighting_Cache"+path+*it; |
66 | if ((config->hasGroup(Group)) && (!force)) | 71 | if ((config->hasGroup(Group)) && (!force)) |
67 | { | 72 | { |
68 | config->setGroup(Group); | 73 | config->setGroup(Group); |
69 | syntaxModeListItem *mli=new syntaxModeListItem; | 74 | syntaxModeListItem *mli=new syntaxModeListItem; |
70 | mli->name = config->readEntry("name",""); | 75 | mli->name = config->readEntry("name",""); |
71 | mli->section = config->readEntry("section",""); | 76 | mli->section = config->readEntry("section",""); |
72 | mli->mimetype = config->readEntry("mimetype",""); | 77 | mli->mimetype = config->readEntry("mimetype",""); |
73 | mli->extension = config->readEntry("extension",""); | 78 | mli->extension = config->readEntry("extension",""); |
74 | mli->identifier = path+*it; | 79 | mli->identifier = path+*it; |
75 | myModeList.append(mli); | 80 | myModeList.append(mli); |
76 | } | 81 | } |
77 | else | 82 | else |
78 | { | 83 | { |
79 | qDebug("Found a description file:"+path+(*it)); | 84 | odebug << "Found a description file:"+path+(*it) << oendl; |
80 | setIdentifier(path+(*it)); | 85 | setIdentifier(path+(*it)); |
81 | Opie::Core::XMLElement *e=m_root; | 86 | Opie::Core::XMLElement *e=m_root; |
82 | if (e) | 87 | if (e) |
83 | { | 88 | { |
84 | e=e->firstChild(); | 89 | e=e->firstChild(); |
85 | qDebug(e->tagName()); | 90 | odebug << e->tagName() << oendl; |
86 | if (e->tagName()=="language") | 91 | if (e->tagName()=="language") |
87 | { | 92 | { |
88 | syntaxModeListItem *mli=new syntaxModeListItem; | 93 | syntaxModeListItem *mli=new syntaxModeListItem; |
89 | mli->name = e->attribute("name"); | 94 | mli->name = e->attribute("name"); |
90 | mli->section = e->attribute("section"); | 95 | mli->section = e->attribute("section"); |
91 | mli->mimetype = e->attribute("mimetype"); | 96 | mli->mimetype = e->attribute("mimetype"); |
92 | mli->extension = e->attribute("extensions"); | 97 | mli->extension = e->attribute("extensions"); |
93 | qDebug(QString("valid description for: %1/%2").arg(mli->section).arg(mli->name)); | 98 | odebug << QString("valid description for: %1/%2").arg(mli->section).arg(mli->name) << oendl; |
94 | if (mli->section.isEmpty()) | 99 | if (mli->section.isEmpty()) |
95 | mli->section=i18n("Other"); | 100 | mli->section=i18n("Other"); |
96 | 101 | ||
97 | mli->identifier = path+(*it); | 102 | mli->identifier = path+(*it); |
98 | config->setGroup(Group); | 103 | config->setGroup(Group); |
99 | config->writeEntry("name",mli->name); | 104 | config->writeEntry("name",mli->name); |
100 | config->writeEntry("section",mli->section); | 105 | config->writeEntry("section",mli->section); |
101 | config->writeEntry("mimetype",mli->mimetype); | 106 | config->writeEntry("mimetype",mli->mimetype); |
102 | config->writeEntry("extension",mli->extension); | 107 | config->writeEntry("extension",mli->extension); |
103 | myModeList.append(mli); | 108 | myModeList.append(mli); |
104 | } | 109 | } |
105 | } | 110 | } |
106 | } | 111 | } |
107 | } | 112 | } |
108 | config->write(); | 113 | config->write(); |
109 | // config->sync(); | 114 | // config->sync(); |
110 | } | 115 | } |
111 | 116 | ||
112 | SyntaxModeList SyntaxDocument::modeList() | 117 | SyntaxModeList SyntaxDocument::modeList() |
113 | { | 118 | { |
114 | return myModeList; | 119 | return myModeList; |
115 | } | 120 | } |
116 | 121 | ||
117 | bool SyntaxDocument::nextGroup( syntaxContextData* data) | 122 | bool SyntaxDocument::nextGroup( syntaxContextData* data) |
@@ -159,148 +164,148 @@ QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name) | |||
159 | else | 164 | else |
160 | return QString(); | 165 | return QString(); |
161 | } | 166 | } |
162 | 167 | ||
163 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) | 168 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) |
164 | { | 169 | { |
165 | if(!data) | 170 | if(!data) |
166 | return QString::null; | 171 | return QString::null; |
167 | 172 | ||
168 | if (data->currentGroup) | 173 | if (data->currentGroup) |
169 | return data->currentGroup->attribute(name); | 174 | return data->currentGroup->attribute(name); |
170 | else | 175 | else |
171 | return QString(); | 176 | return QString(); |
172 | } | 177 | } |
173 | 178 | ||
174 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) | 179 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) |
175 | { | 180 | { |
176 | if (data) | 181 | if (data) |
177 | delete data; | 182 | delete data; |
178 | } | 183 | } |
179 | 184 | ||
180 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) | 185 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) |
181 | { | 186 | { |
182 | syntaxContextData *retval=new syntaxContextData; | 187 | syntaxContextData *retval=new syntaxContextData; |
183 | retval->parent=0; | 188 | retval->parent=0; |
184 | retval->currentGroup=0; | 189 | retval->currentGroup=0; |
185 | retval->item=0; | 190 | retval->item=0; |
186 | if (data != 0) | 191 | if (data != 0) |
187 | { | 192 | { |
188 | retval->parent=data->currentGroup; | 193 | retval->parent=data->currentGroup; |
189 | retval->currentGroup=data->item; | 194 | retval->currentGroup=data->item; |
190 | retval->item=0; | 195 | retval->item=0; |
191 | } | 196 | } |
192 | 197 | ||
193 | return retval; | 198 | return retval; |
194 | } | 199 | } |
195 | 200 | ||
196 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) | 201 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) |
197 | { | 202 | { |
198 | Opie::Core::XMLElement *e = m_root->firstChild()->firstChild(); | 203 | Opie::Core::XMLElement *e = m_root->firstChild()->firstChild(); |
199 | 204 | ||
200 | while (e) | 205 | while (e) |
201 | { | 206 | { |
202 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 207 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
203 | 208 | ||
204 | if (e->tagName().compare(mainGroupName)==0 ) | 209 | if (e->tagName().compare(mainGroupName)==0 ) |
205 | { | 210 | { |
206 | Opie::Core::XMLElement *e1=e->firstChild(); | 211 | Opie::Core::XMLElement *e1=e->firstChild(); |
207 | 212 | ||
208 | while (e1) | 213 | while (e1) |
209 | { | 214 | { |
210 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 215 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
211 | 216 | ||
212 | if (e1->tagName()==Config) | 217 | if (e1->tagName()==Config) |
213 | { | 218 | { |
214 | syntaxContextData *data=new ( syntaxContextData); | 219 | syntaxContextData *data=new ( syntaxContextData); |
215 | data->currentGroup=0; | 220 | data->currentGroup=0; |
216 | data->parent=0; | 221 | data->parent=0; |
217 | data->item=e1; | 222 | data->item=e1; |
218 | return data; | 223 | return data; |
219 | } | 224 | } |
220 | 225 | ||
221 | e1=e1->nextChild(); | 226 | e1=e1->nextChild(); |
222 | } | 227 | } |
223 | 228 | ||
224 | kdDebug(13010) << "WARNING :returning null 3"<< endl; | 229 | kdDebug(13010) << "WARNING :returning null 3"<< endl; |
225 | return 0; | 230 | return 0; |
226 | } | 231 | } |
227 | 232 | ||
228 | e=e->nextChild(); | 233 | e=e->nextChild(); |
229 | } | 234 | } |
230 | 235 | ||
231 | kdDebug(13010) << "WARNING :returning null 4" << endl; | 236 | kdDebug(13010) << "WARNING :returning null 4" << endl; |
232 | return 0; | 237 | return 0; |
233 | } | 238 | } |
234 | 239 | ||
235 | 240 | ||
236 | 241 | ||
237 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) | 242 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) |
238 | { | 243 | { |
239 | 244 | ||
240 | Opie::Core::XMLElement *e=m_root->firstChild()->firstChild(); | 245 | Opie::Core::XMLElement *e=m_root->firstChild()->firstChild(); |
241 | 246 | ||
242 | while (e) | 247 | while (e) |
243 | { | 248 | { |
244 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 249 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
245 | 250 | ||
246 | if (e->tagName().compare(mainGroupName)==0 ) | 251 | if (e->tagName().compare(mainGroupName)==0 ) |
247 | { | 252 | { |
248 | Opie::Core::XMLElement *e1=e->firstChild(); | 253 | Opie::Core::XMLElement *e1=e->firstChild(); |
249 | 254 | ||
250 | while (e1) | 255 | while (e1) |
251 | { | 256 | { |
252 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 257 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
253 | if (e1->tagName()==group+"s") | 258 | if (e1->tagName()==group+"s") |
254 | { | 259 | { |
255 | syntaxContextData *data=new ( syntaxContextData); | 260 | syntaxContextData *data=new ( syntaxContextData); |
256 | data->parent=e1; | 261 | data->parent=e1; |
257 | data->currentGroup=0; | 262 | data->currentGroup=0; |
258 | data->item=0; | 263 | data->item=0; |
259 | return data; | 264 | return data; |
260 | } | 265 | } |
261 | 266 | ||
262 | e1=e1->nextChild(); | 267 | e1=e1->nextChild(); |
263 | } | 268 | } |
264 | 269 | ||
265 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; | 270 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; |
266 | return 0; | 271 | return 0; |
267 | } | 272 | } |
268 | 273 | ||
269 | e=e->nextChild(); | 274 | e=e->nextChild(); |
270 | } | 275 | } |
271 | 276 | ||
272 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; | 277 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; |
273 | return 0; | 278 | return 0; |
274 | } | 279 | } |
275 | 280 | ||
276 | 281 | ||
277 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) | 282 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) |
278 | { | 283 | { |
279 | Opie::Core::XMLElement *e = m_root->firstChild(); | 284 | Opie::Core::XMLElement *e = m_root->firstChild(); |
280 | if (clearList) | 285 | if (clearList) |
281 | m_data.clear(); | 286 | m_data.clear(); |
282 | 287 | ||
283 | for(e=e->firstChild(); e; e=e->nextChild()) | 288 | for(e=e->firstChild(); e; e=e->nextChild()) |
284 | { | 289 | { |
285 | if (e->tagName()==mainGroup) | 290 | if (e->tagName()==mainGroup) |
286 | { | 291 | { |
287 | for (Opie::Core::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) | 292 | for (Opie::Core::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) |
288 | { | 293 | { |
289 | if (e1->tagName()!="list") continue; | 294 | if (e1->tagName()!="list") continue; |
290 | 295 | ||
291 | if (e1->attribute("name")==type) | 296 | if (e1->attribute("name")==type) |
292 | { | 297 | { |
293 | for (Opie::Core::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) | 298 | for (Opie::Core::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) |
294 | { | 299 | { |
295 | qDebug("FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->firstChild()->value()); | 300 | odebug << "FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->firstChild()->value() << oendl; |
296 | m_data+=e2->firstChild()->value().stripWhiteSpace(); | 301 | m_data+=e2->firstChild()->value().stripWhiteSpace(); |
297 | } | 302 | } |
298 | break; | 303 | break; |
299 | } | 304 | } |
300 | } | 305 | } |
301 | break; | 306 | break; |
302 | } | 307 | } |
303 | } | 308 | } |
304 | 309 | ||
305 | return m_data; | 310 | return m_data; |
306 | } | 311 | } |
diff --git a/noncore/apps/tinykate/libkate/kateconfig.cpp b/noncore/apps/tinykate/libkate/kateconfig.cpp index 96f91fb..782b629 100644 --- a/noncore/apps/tinykate/libkate/kateconfig.cpp +++ b/noncore/apps/tinykate/libkate/kateconfig.cpp | |||
@@ -1,632 +1,637 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 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 | #define QTOPIA_INTERNAL_LANGLIST | ||
22 | #include "kateconfig.h" | ||
23 | |||
24 | /* OPIE */ | ||
25 | #include <opie2/odebug.h> | ||
26 | #include <qpe/global.h> | ||
27 | |||
28 | /* QT */ | ||
21 | #include <qdir.h> | 29 | #include <qdir.h> |
22 | #include <qmessagebox.h> | 30 | #include <qmessagebox.h> |
23 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 31 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
24 | #include <qtextcodec.h> | 32 | #include <qtextcodec.h> |
25 | #endif | 33 | #endif |
26 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
27 | 35 | ||
36 | /* STD */ | ||
28 | #include <sys/stat.h> | 37 | #include <sys/stat.h> |
29 | #include <sys/types.h> | 38 | #include <sys/types.h> |
30 | #include <fcntl.h> | 39 | #include <fcntl.h> |
31 | #include <stdlib.h> | 40 | #include <stdlib.h> |
32 | #include <unistd.h> | 41 | #include <unistd.h> |
33 | 42 | ||
34 | #define QTOPIA_INTERNAL_LANGLIST | ||
35 | #include "kateconfig.h" | ||
36 | #include <qpe/global.h> | ||
37 | |||
38 | 43 | ||
39 | /*! | 44 | /*! |
40 | \internal | 45 | \internal |
41 | */ | 46 | */ |
42 | QString KateConfig::configFilename(const QString& name, Domain d) | 47 | QString KateConfig::configFilename(const QString& name, Domain d) |
43 | { | 48 | { |
44 | switch (d) { | 49 | switch (d) { |
45 | case File: | 50 | case File: |
46 | return name; | 51 | return name; |
47 | case User: { | 52 | case User: { |
48 | QDir dir = (QString(getenv("HOME")) + "/Settings"); | 53 | QDir dir = (QString(getenv("HOME")) + "/Settings"); |
49 | if ( !dir.exists() ) | 54 | if ( !dir.exists() ) |
50 | mkdir(dir.path().local8Bit(),0700); | 55 | mkdir(dir.path().local8Bit(),0700); |
51 | return dir.path() + "/" + name + ".conf"; | 56 | return dir.path() + "/" + name + ".conf"; |
52 | } | 57 | } |
53 | } | 58 | } |
54 | return name; | 59 | return name; |
55 | } | 60 | } |
56 | 61 | ||
57 | /*! | 62 | /*! |
58 | \class KateConfig config.h | 63 | \class KateConfig config.h |
59 | \brief The KateConfig class provides for saving application cofniguration state. | 64 | \brief The KateConfig class provides for saving application cofniguration state. |
60 | 65 | ||
61 | You should keep a KateConfig in existence only while you do not want others | 66 | You should keep a KateConfig in existence only while you do not want others |
62 | to be able to change the state. There is no locking currently, but there | 67 | to be able to change the state. There is no locking currently, but there |
63 | may be in the future. | 68 | may be in the future. |
64 | */ | 69 | */ |
65 | 70 | ||
66 | /*! | 71 | /*! |
67 | \enum KateConfig::KateConfigGroup | 72 | \enum KateConfig::KateConfigGroup |
68 | \internal | 73 | \internal |
69 | */ | 74 | */ |
70 | 75 | ||
71 | /*! | 76 | /*! |
72 | \enum KateConfig::Domain | 77 | \enum KateConfig::Domain |
73 | 78 | ||
74 | \value File | 79 | \value File |
75 | \value User | 80 | \value User |
76 | 81 | ||
77 | See KateConfig for details. | 82 | See KateConfig for details. |
78 | */ | 83 | */ |
79 | 84 | ||
80 | /*! | 85 | /*! |
81 | Constructs a config that will load or create a configuration with the | 86 | Constructs a config that will load or create a configuration with the |
82 | given \a name in the given \a domain. | 87 | given \a name in the given \a domain. |
83 | 88 | ||
84 | You must call setGroup() before doing much else with the KateConfig. | 89 | You must call setGroup() before doing much else with the KateConfig. |
85 | 90 | ||
86 | In the default Domain, \e User, | 91 | In the default Domain, \e User, |
87 | the configuration is user-specific. \a name should not contain "/" in | 92 | the configuration is user-specific. \a name should not contain "/" in |
88 | this case, and in general should be the name of the C++ class that is | 93 | this case, and in general should be the name of the C++ class that is |
89 | primarily responsible for maintaining the configuration. | 94 | primarily responsible for maintaining the configuration. |
90 | 95 | ||
91 | In the File Domain, \a name is an absolute filename. | 96 | In the File Domain, \a name is an absolute filename. |
92 | */ | 97 | */ |
93 | KateConfig::KateConfig( const QString &name, Domain domain ) | 98 | KateConfig::KateConfig( const QString &name, Domain domain ) |
94 | : filename( configFilename(name,domain) ) | 99 | : filename( configFilename(name,domain) ) |
95 | { | 100 | { |
96 | qWarning("KateConfig constructor\n"); | 101 | owarn << "KateConfig constructor\n" << oendl; |
97 | git = groups.end(); | 102 | git = groups.end(); |
98 | read(); | 103 | read(); |
99 | QStringList l = Global::languageList(); | 104 | QStringList l = Global::languageList(); |
100 | lang = l[0]; | 105 | lang = l[0]; |
101 | glang = l[1]; | 106 | glang = l[1]; |
102 | } | 107 | } |
103 | 108 | ||
104 | 109 | ||
105 | // Sharp ROM compatibility | 110 | // Sharp ROM compatibility |
106 | KateConfig::KateConfig ( const QString &name, bool what ) | 111 | KateConfig::KateConfig ( const QString &name, bool what ) |
107 | : filename( configFilename(name,what ? User : File) ) | 112 | : filename( configFilename(name,what ? User : File) ) |
108 | { | 113 | { |
109 | git = groups.end(); | 114 | git = groups.end(); |
110 | read(); | 115 | read(); |
111 | QStringList l = Global::languageList(); | 116 | QStringList l = Global::languageList(); |
112 | lang = l[0]; | 117 | lang = l[0]; |
113 | glang = l[1]; | 118 | glang = l[1]; |
114 | } | 119 | } |
115 | 120 | ||
116 | /*! | 121 | /*! |
117 | Writes any changes to disk and destroys the in-memory object. | 122 | Writes any changes to disk and destroys the in-memory object. |
118 | */ | 123 | */ |
119 | KateConfig::~KateConfig() | 124 | KateConfig::~KateConfig() |
120 | { | 125 | { |
121 | qWarning("KateConfig destructor\n"); | 126 | owarn << "KateConfig destructor\n" << oendl; |
122 | if ( changed ) | 127 | if ( changed ) |
123 | write(); | 128 | write(); |
124 | } | 129 | } |
125 | 130 | ||
126 | /*! | 131 | /*! |
127 | Returns whether the current group has an entry called \a key. | 132 | Returns whether the current group has an entry called \a key. |
128 | */ | 133 | */ |
129 | bool KateConfig::hasKey( const QString &key ) const | 134 | bool KateConfig::hasKey( const QString &key ) const |
130 | { | 135 | { |
131 | if ( groups.end() == git ) | 136 | if ( groups.end() == git ) |
132 | return FALSE; | 137 | return FALSE; |
133 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); | 138 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); |
134 | return it != ( *git ).end(); | 139 | return it != ( *git ).end(); |
135 | } | 140 | } |
136 | 141 | ||
137 | /*! | 142 | /*! |
138 | Sets the current group for subsequent reading and writing of | 143 | Sets the current group for subsequent reading and writing of |
139 | entries to \a gname. Grouping allows the application to partition the namespace. | 144 | entries to \a gname. Grouping allows the application to partition the namespace. |
140 | 145 | ||
141 | This function must be called prior to any reading or writing | 146 | This function must be called prior to any reading or writing |
142 | of entries. | 147 | of entries. |
143 | 148 | ||
144 | The \a gname must not be empty. | 149 | The \a gname must not be empty. |
145 | */ | 150 | */ |
146 | void KateConfig::setGroup( const QString &gname ) | 151 | void KateConfig::setGroup( const QString &gname ) |
147 | { | 152 | { |
148 | QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname ); | 153 | QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname ); |
149 | if ( it == groups.end() ) { | 154 | if ( it == groups.end() ) { |
150 | git = groups.insert( gname, KateConfigGroup() ); | 155 | git = groups.insert( gname, KateConfigGroup() ); |
151 | changed = TRUE; | 156 | changed = TRUE; |
152 | return; | 157 | return; |
153 | } | 158 | } |
154 | git = it; | 159 | git = it; |
155 | } | 160 | } |
156 | 161 | ||
157 | /*! | 162 | /*! |
158 | Writes a (\a key, \a value) entry to the current group. | 163 | Writes a (\a key, \a value) entry to the current group. |
159 | 164 | ||
160 | \sa readEntry() | 165 | \sa readEntry() |
161 | */ | 166 | */ |
162 | void KateConfig::writeEntry( const QString &key, const char* value ) | 167 | void KateConfig::writeEntry( const QString &key, const char* value ) |
163 | { | 168 | { |
164 | writeEntry(key,QString(value)); | 169 | writeEntry(key,QString(value)); |
165 | } | 170 | } |
166 | 171 | ||
167 | /*! | 172 | /*! |
168 | Writes a (\a key, \a value) entry to the current group. | 173 | Writes a (\a key, \a value) entry to the current group. |
169 | 174 | ||
170 | \sa readEntry() | 175 | \sa readEntry() |
171 | */ | 176 | */ |
172 | void KateConfig::writeEntry( const QString &key, const QString &value ) | 177 | void KateConfig::writeEntry( const QString &key, const QString &value ) |
173 | { | 178 | { |
174 | if ( git == groups.end() ) { | 179 | if ( git == groups.end() ) { |
175 | qWarning( "no group set" ); | 180 | owarn << "no group set" << oendl; |
176 | return; | 181 | return; |
177 | } | 182 | } |
178 | if ( (*git)[key] != value ) { | 183 | if ( (*git)[key] != value ) { |
179 | ( *git ).insert( key, value ); | 184 | ( *git ).insert( key, value ); |
180 | changed = TRUE; | 185 | changed = TRUE; |
181 | } | 186 | } |
182 | } | 187 | } |
183 | 188 | ||
184 | /* | 189 | /* |
185 | Note that the degree of protection offered by the encryption here is | 190 | Note that the degree of protection offered by the encryption here is |
186 | only sufficient to avoid the most casual observation of the configuration | 191 | only sufficient to avoid the most casual observation of the configuration |
187 | files. People with access to the files can write down the contents and | 192 | files. People with access to the files can write down the contents and |
188 | decrypt it using this source code. | 193 | decrypt it using this source code. |
189 | 194 | ||
190 | Conceivably, and at some burden to the user, this encryption could | 195 | Conceivably, and at some burden to the user, this encryption could |
191 | be improved. | 196 | be improved. |
192 | */ | 197 | */ |
193 | static QString encipher(const QString& plain) | 198 | static QString encipher(const QString& plain) |
194 | { | 199 | { |
195 | // mainly, we make it long | 200 | // mainly, we make it long |
196 | QString cipher; | 201 | QString cipher; |
197 | int mix=28730492; | 202 | int mix=28730492; |
198 | for (int i=0; i<(int)plain.length(); i++) { | 203 | for (int i=0; i<(int)plain.length(); i++) { |
199 | int u = plain[i].unicode(); | 204 | int u = plain[i].unicode(); |
200 | int c = u ^ mix; | 205 | int c = u ^ mix; |
201 | QString x = QString::number(c,36); | 206 | QString x = QString::number(c,36); |
202 | cipher.append(QChar('a'+x.length())); | 207 | cipher.append(QChar('a'+x.length())); |
203 | cipher.append(x); | 208 | cipher.append(x); |
204 | mix *= u; | 209 | mix *= u; |
205 | } | 210 | } |
206 | return cipher; | 211 | return cipher; |
207 | } | 212 | } |
208 | 213 | ||
209 | static QString decipher(const QString& cipher) | 214 | static QString decipher(const QString& cipher) |
210 | { | 215 | { |
211 | QString plain; | 216 | QString plain; |
212 | int mix=28730492; | 217 | int mix=28730492; |
213 | for (int i=0; i<(int)cipher.length();) { | 218 | for (int i=0; i<(int)cipher.length();) { |
214 | int l = cipher[i].unicode()-'a'; | 219 | int l = cipher[i].unicode()-'a'; |
215 | QString x = cipher.mid(i+1,l); i+=l+1; | 220 | QString x = cipher.mid(i+1,l); i+=l+1; |
216 | int u = x.toInt(0,36) ^ mix; | 221 | int u = x.toInt(0,36) ^ mix; |
217 | plain.append(QChar(u)); | 222 | plain.append(QChar(u)); |
218 | mix *= u; | 223 | mix *= u; |
219 | } | 224 | } |
220 | return plain; | 225 | return plain; |
221 | } | 226 | } |
222 | 227 | ||
223 | /*! | 228 | /*! |
224 | Writes an encrypted (\a key, \a value) entry to the current group. | 229 | Writes an encrypted (\a key, \a value) entry to the current group. |
225 | 230 | ||
226 | Note that the degree of protection offered by the encryption is | 231 | Note that the degree of protection offered by the encryption is |
227 | only sufficient to avoid the most casual observation of the configuration | 232 | only sufficient to avoid the most casual observation of the configuration |
228 | files. | 233 | files. |
229 | 234 | ||
230 | \sa readEntry() | 235 | \sa readEntry() |
231 | */ | 236 | */ |
232 | void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) | 237 | void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) |
233 | { | 238 | { |
234 | if ( git == groups.end() ) { | 239 | if ( git == groups.end() ) { |
235 | qWarning( "no group set" ); | 240 | owarn << "no group set" << oendl; |
236 | return; | 241 | return; |
237 | } | 242 | } |
238 | QString evalue = encipher(value); | 243 | QString evalue = encipher(value); |
239 | if ( (*git)[key] != evalue ) { | 244 | if ( (*git)[key] != evalue ) { |
240 | ( *git ).insert( key, evalue ); | 245 | ( *git ).insert( key, evalue ); |
241 | changed = TRUE; | 246 | changed = TRUE; |
242 | } | 247 | } |
243 | } | 248 | } |
244 | 249 | ||
245 | /*! | 250 | /*! |
246 | Writes a (\a key, \a num) entry to the current group. | 251 | Writes a (\a key, \a num) entry to the current group. |
247 | 252 | ||
248 | \sa readNumEntry() | 253 | \sa readNumEntry() |
249 | */ | 254 | */ |
250 | void KateConfig::writeEntry( const QString &key, int num ) | 255 | void KateConfig::writeEntry( const QString &key, int num ) |
251 | { | 256 | { |
252 | QString s; | 257 | QString s; |
253 | s.setNum( num ); | 258 | s.setNum( num ); |
254 | writeEntry( key, s ); | 259 | writeEntry( key, s ); |
255 | } | 260 | } |
256 | 261 | ||
257 | void KateConfig::writeEntry( const QString &key, unsigned int num ) | 262 | void KateConfig::writeEntry( const QString &key, unsigned int num ) |
258 | { | 263 | { |
259 | QString s; | 264 | QString s; |
260 | s.setNum( num ); | 265 | s.setNum( num ); |
261 | writeEntry( key, s ); | 266 | writeEntry( key, s ); |
262 | } | 267 | } |
263 | 268 | ||
264 | #ifdef Q_HAS_BOOL_TYPE | 269 | #ifdef Q_HAS_BOOL_TYPE |
265 | /*! | 270 | /*! |
266 | Writes a (\a key, \a b) entry to the current group. This is equivalent | 271 | Writes a (\a key, \a b) entry to the current group. This is equivalent |
267 | to writing a 0 or 1 as an integer entry. | 272 | to writing a 0 or 1 as an integer entry. |
268 | 273 | ||
269 | \sa readBoolEntry() | 274 | \sa readBoolEntry() |
270 | */ | 275 | */ |
271 | void KateConfig::writeEntry( const QString &key, bool b ) | 276 | void KateConfig::writeEntry( const QString &key, bool b ) |
272 | { | 277 | { |
273 | QString s; | 278 | QString s; |
274 | s.setNum( ( int )b ); | 279 | s.setNum( ( int )b ); |
275 | writeEntry( key, s ); | 280 | writeEntry( key, s ); |
276 | } | 281 | } |
277 | #endif | 282 | #endif |
278 | 283 | ||
279 | /*! | 284 | /*! |
280 | Writes a (\a key, \a lst) entry to the current group. The list | 285 | Writes a (\a key, \a lst) entry to the current group. The list |
281 | is separated by \a sep, so the strings must not contain that character. | 286 | is separated by \a sep, so the strings must not contain that character. |
282 | 287 | ||
283 | \sa readListEntry() | 288 | \sa readListEntry() |
284 | */ | 289 | */ |
285 | void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) | 290 | void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) |
286 | { | 291 | { |
287 | QString s; | 292 | QString s; |
288 | QStringList::ConstIterator it = lst.begin(); | 293 | QStringList::ConstIterator it = lst.begin(); |
289 | for ( ; it != lst.end(); ++it ) | 294 | for ( ; it != lst.end(); ++it ) |
290 | s += *it + sep; | 295 | s += *it + sep; |
291 | writeEntry( key, s ); | 296 | writeEntry( key, s ); |
292 | } | 297 | } |
293 | 298 | ||
294 | void KateConfig::writeEntry( const QString &key, const QColor &val ) | 299 | void KateConfig::writeEntry( const QString &key, const QColor &val ) |
295 | { | 300 | { |
296 | QStringList l; | 301 | QStringList l; |
297 | l.append( QString().setNum(val.red()) ); | 302 | l.append( QString().setNum(val.red()) ); |
298 | l.append( QString().setNum(val.green()) ); | 303 | l.append( QString().setNum(val.green()) ); |
299 | l.append( QString().setNum(val.blue()) ); | 304 | l.append( QString().setNum(val.blue()) ); |
300 | 305 | ||
301 | writeEntry( key, l, QChar(',') ); | 306 | writeEntry( key, l, QChar(',') ); |
302 | } | 307 | } |
303 | 308 | ||
304 | void KateConfig::writeEntry( const QString &key, const QFont &val ) | 309 | void KateConfig::writeEntry( const QString &key, const QFont &val ) |
305 | { | 310 | { |
306 | QStringList l; | 311 | QStringList l; |
307 | l.append( val.family() ); | 312 | l.append( val.family() ); |
308 | l.append( QString().setNum(val.pointSize()) ); | 313 | l.append( QString().setNum(val.pointSize()) ); |
309 | l.append( QString().setNum(val.weight()) ); | 314 | l.append( QString().setNum(val.weight()) ); |
310 | l.append( QString().setNum((int)val.italic()) ); | 315 | l.append( QString().setNum((int)val.italic()) ); |
311 | l.append( QString().setNum((int)val.charSet()) ); | 316 | l.append( QString().setNum((int)val.charSet()) ); |
312 | 317 | ||
313 | writeEntry( key, l, QChar(',') ); | 318 | writeEntry( key, l, QChar(',') ); |
314 | } | 319 | } |
315 | 320 | ||
316 | /*! | 321 | /*! |
317 | Removes the \a key entry from the current group. Does nothing if | 322 | Removes the \a key entry from the current group. Does nothing if |
318 | there is no such entry. | 323 | there is no such entry. |
319 | */ | 324 | */ |
320 | 325 | ||
321 | void KateConfig::removeEntry( const QString &key ) | 326 | void KateConfig::removeEntry( const QString &key ) |
322 | { | 327 | { |
323 | if ( git == groups.end() ) { | 328 | if ( git == groups.end() ) { |
324 | qWarning( "no group set" ); | 329 | owarn << "no group set" << oendl; |
325 | return; | 330 | return; |
326 | } | 331 | } |
327 | ( *git ).remove( key ); | 332 | ( *git ).remove( key ); |
328 | changed = TRUE; | 333 | changed = TRUE; |
329 | } | 334 | } |
330 | 335 | ||
331 | /*! | 336 | /*! |
332 | \fn bool KateConfig::operator == ( const KateConfig & other ) const | 337 | \fn bool KateConfig::operator == ( const KateConfig & other ) const |
333 | 338 | ||
334 | Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename. | 339 | Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename. |
335 | */ | 340 | */ |
336 | 341 | ||
337 | /*! | 342 | /*! |
338 | \fn bool KateConfig::operator != ( const KateConfig & other ) const | 343 | \fn bool KateConfig::operator != ( const KateConfig & other ) const |
339 | 344 | ||
340 | Tests for inequality with \a other. KateConfig objects are equal if they refer to the same filename. | 345 | Tests for inequality with \a other. KateConfig objects are equal if they refer to the same filename. |
341 | */ | 346 | */ |
342 | 347 | ||
343 | /*! | 348 | /*! |
344 | \fn QString KateConfig::readEntry( const QString &key, const QString &deflt ) const | 349 | \fn QString KateConfig::readEntry( const QString &key, const QString &deflt ) const |
345 | 350 | ||
346 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. | 351 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. |
347 | */ | 352 | */ |
348 | 353 | ||
349 | /*! | 354 | /*! |
350 | \internal | 355 | \internal |
351 | For compatibility, non-const version. | 356 | For compatibility, non-const version. |
352 | */ | 357 | */ |
353 | QString KateConfig::readEntry( const QString &key, const QString &deflt ) | 358 | QString KateConfig::readEntry( const QString &key, const QString &deflt ) |
354 | { | 359 | { |
355 | QString res = readEntryDirect( key+"["+lang+"]" ); | 360 | QString res = readEntryDirect( key+"["+lang+"]" ); |
356 | if ( !res.isNull() ) | 361 | if ( !res.isNull() ) |
357 | return res; | 362 | return res; |
358 | if ( !glang.isEmpty() ) { | 363 | if ( !glang.isEmpty() ) { |
359 | res = readEntryDirect( key+"["+glang+"]" ); | 364 | res = readEntryDirect( key+"["+glang+"]" ); |
360 | if ( !res.isNull() ) | 365 | if ( !res.isNull() ) |
361 | return res; | 366 | return res; |
362 | } | 367 | } |
363 | return readEntryDirect( key, deflt ); | 368 | return readEntryDirect( key, deflt ); |
364 | } | 369 | } |
365 | 370 | ||
366 | /*! | 371 | /*! |
367 | \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const | 372 | \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const |
368 | 373 | ||
369 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. | 374 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. |
370 | */ | 375 | */ |
371 | 376 | ||
372 | /*! | 377 | /*! |
373 | \internal | 378 | \internal |
374 | For compatibility, non-const version. | 379 | For compatibility, non-const version. |
375 | */ | 380 | */ |
376 | QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) | 381 | QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) |
377 | { | 382 | { |
378 | QString res = readEntryDirect( key+"["+lang+"]" ); | 383 | QString res = readEntryDirect( key+"["+lang+"]" ); |
379 | if ( res.isNull() && glang.isEmpty() ) | 384 | if ( res.isNull() && glang.isEmpty() ) |
380 | res = readEntryDirect( key+"["+glang+"]" ); | 385 | res = readEntryDirect( key+"["+glang+"]" ); |
381 | if ( res.isNull() ) | 386 | if ( res.isNull() ) |
382 | res = readEntryDirect( key, QString::null ); | 387 | res = readEntryDirect( key, QString::null ); |
383 | if ( res.isNull() ) | 388 | if ( res.isNull() ) |
384 | return deflt; | 389 | return deflt; |
385 | return decipher(res); | 390 | return decipher(res); |
386 | } | 391 | } |
387 | 392 | ||
388 | /*! | 393 | /*! |
389 | \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const | 394 | \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const |
390 | \internal | 395 | \internal |
391 | */ | 396 | */ |
392 | 397 | ||
393 | /*! | 398 | /*! |
394 | \internal | 399 | \internal |
395 | For compatibility, non-const version. | 400 | For compatibility, non-const version. |
396 | */ | 401 | */ |
397 | QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) | 402 | QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) |
398 | { | 403 | { |
399 | if ( git == groups.end() ) { | 404 | if ( git == groups.end() ) { |
400 | //qWarning( "no group set" ); | 405 | //owarn << "no group set" << oendl; |
401 | return deflt; | 406 | return deflt; |
402 | } | 407 | } |
403 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); | 408 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); |
404 | if ( it != ( *git ).end() ) | 409 | if ( it != ( *git ).end() ) |
405 | return *it; | 410 | return *it; |
406 | else | 411 | else |
407 | return deflt; | 412 | return deflt; |
408 | } | 413 | } |
409 | 414 | ||
410 | /*! | 415 | /*! |
411 | \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const | 416 | \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const |
412 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. | 417 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. |
413 | */ | 418 | */ |
414 | 419 | ||
415 | /*! | 420 | /*! |
416 | \internal | 421 | \internal |
417 | For compatibility, non-const version. | 422 | For compatibility, non-const version. |
418 | */ | 423 | */ |
419 | int KateConfig::readNumEntry( const QString &key, int deflt ) | 424 | int KateConfig::readNumEntry( const QString &key, int deflt ) |
420 | { | 425 | { |
421 | QString s = readEntry( key ); | 426 | QString s = readEntry( key ); |
422 | if ( s.isEmpty() ) | 427 | if ( s.isEmpty() ) |
423 | return deflt; | 428 | return deflt; |
424 | else | 429 | else |
425 | return s.toInt(); | 430 | return s.toInt(); |
426 | } | 431 | } |
427 | 432 | ||
428 | /*! | 433 | /*! |
429 | \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const | 434 | \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const |
430 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. | 435 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. |
431 | */ | 436 | */ |
432 | 437 | ||
433 | /*! | 438 | /*! |
434 | \internal | 439 | \internal |
435 | For compatibility, non-const version. | 440 | For compatibility, non-const version. |
436 | */ | 441 | */ |
437 | bool KateConfig::readBoolEntry( const QString &key, bool deflt ) | 442 | bool KateConfig::readBoolEntry( const QString &key, bool deflt ) |
438 | { | 443 | { |
439 | QString s = readEntry( key ); | 444 | QString s = readEntry( key ); |
440 | if ( s.isEmpty() ) | 445 | if ( s.isEmpty() ) |
441 | return deflt; | 446 | return deflt; |
442 | else | 447 | else |
443 | return (bool)s.toInt(); | 448 | return (bool)s.toInt(); |
444 | } | 449 | } |
445 | 450 | ||
446 | /*! | 451 | /*! |
447 | \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const | 452 | \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const |
448 | Reads a string list entry stored with \a key, and with \a sep as the separator. | 453 | Reads a string list entry stored with \a key, and with \a sep as the separator. |
449 | */ | 454 | */ |
450 | 455 | ||
451 | /*! | 456 | /*! |
452 | \internal | 457 | \internal |
453 | For compatibility, non-const version. | 458 | For compatibility, non-const version. |
454 | */ | 459 | */ |
455 | QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) | 460 | QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) |
456 | { | 461 | { |
457 | QString s = readEntry( key ); | 462 | QString s = readEntry( key ); |
458 | if ( s.isEmpty() ) | 463 | if ( s.isEmpty() ) |
459 | return QStringList(); | 464 | return QStringList(); |
460 | else | 465 | else |
461 | return QStringList::split( sep, s ); | 466 | return QStringList::split( sep, s ); |
462 | } | 467 | } |
463 | 468 | ||
464 | QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const | 469 | QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const |
465 | { | 470 | { |
466 | QStringList list = readListEntry(key, QChar(',')); | 471 | QStringList list = readListEntry(key, QChar(',')); |
467 | if( list.count() != 3 ) | 472 | if( list.count() != 3 ) |
468 | return def; | 473 | return def; |
469 | 474 | ||
470 | return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt()); | 475 | return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt()); |
471 | } | 476 | } |
472 | 477 | ||
473 | QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const | 478 | QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const |
474 | { | 479 | { |
475 | QStringList list = readListEntry(key, QChar(',')); | 480 | QStringList list = readListEntry(key, QChar(',')); |
476 | if( list.count() != 5 ) | 481 | if( list.count() != 5 ) |
477 | return def; | 482 | return def; |
478 | 483 | ||
479 | return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt()); | 484 | return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt()); |
480 | } | 485 | } |
481 | 486 | ||
482 | QValueList<int> KateConfig::readIntListEntry( const QString &key ) const | 487 | QValueList<int> KateConfig::readIntListEntry( const QString &key ) const |
483 | { | 488 | { |
484 | QString s = readEntry( key ); | 489 | QString s = readEntry( key ); |
485 | QValueList<int> il; | 490 | QValueList<int> il; |
486 | if ( s.isEmpty() ) | 491 | if ( s.isEmpty() ) |
487 | return il; | 492 | return il; |
488 | 493 | ||
489 | QStringList l = QStringList::split( QChar(','), s ); | 494 | QStringList l = QStringList::split( QChar(','), s ); |
490 | 495 | ||
491 | QStringList::Iterator l_it; | 496 | QStringList::Iterator l_it; |
492 | for( l_it = l.begin(); l_it != l.end(); ++l_it ) | 497 | for( l_it = l.begin(); l_it != l.end(); ++l_it ) |
493 | il.append( (*l_it).toInt() ); | 498 | il.append( (*l_it).toInt() ); |
494 | return il; | 499 | return il; |
495 | } | 500 | } |
496 | 501 | ||
497 | /*! | 502 | /*! |
498 | Removes all entries from the current group. | 503 | Removes all entries from the current group. |
499 | */ | 504 | */ |
500 | void KateConfig::clearGroup() | 505 | void KateConfig::clearGroup() |
501 | { | 506 | { |
502 | if ( git == groups.end() ) { | 507 | if ( git == groups.end() ) { |
503 | qWarning( "no group set" ); | 508 | owarn << "no group set" << oendl; |
504 | return; | 509 | return; |
505 | } | 510 | } |
506 | if ( !(*git).isEmpty() ) { | 511 | if ( !(*git).isEmpty() ) { |
507 | ( *git ).clear(); | 512 | ( *git ).clear(); |
508 | changed = TRUE; | 513 | changed = TRUE; |
509 | } | 514 | } |
510 | } | 515 | } |
511 | 516 | ||
512 | /*! | 517 | /*! |
513 | \internal | 518 | \internal |
514 | */ | 519 | */ |
515 | void KateConfig::write( const QString &fn ) | 520 | void KateConfig::write( const QString &fn ) |
516 | { | 521 | { |
517 | QString strNewFile; | 522 | QString strNewFile; |
518 | if ( !fn.isEmpty() ) | 523 | if ( !fn.isEmpty() ) |
519 | filename = fn; | 524 | filename = fn; |
520 | strNewFile = filename + ".new"; | 525 | strNewFile = filename + ".new"; |
521 | 526 | ||
522 | QFile f( strNewFile ); | 527 | QFile f( strNewFile ); |
523 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { | 528 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { |
524 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); | 529 | owarn << "could not open for writing `" << strNewFile << "'" << oendl; |
525 | git = groups.end(); | 530 | git = groups.end(); |
526 | return; | 531 | return; |
527 | } | 532 | } |
528 | 533 | ||
529 | QString str; | 534 | QString str; |
530 | QCString cstr; | 535 | QCString cstr; |
531 | QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); | 536 | QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); |
532 | 537 | ||
533 | for ( ; g_it != groups.end(); ++g_it ) { | 538 | for ( ; g_it != groups.end(); ++g_it ) { |
534 | str += "[" + g_it.key() + "]\n"; | 539 | str += "[" + g_it.key() + "]\n"; |
535 | KateConfigGroup::Iterator e_it = ( *g_it ).begin(); | 540 | KateConfigGroup::Iterator e_it = ( *g_it ).begin(); |
536 | for ( ; e_it != ( *g_it ).end(); ++e_it ) | 541 | for ( ; e_it != ( *g_it ).end(); ++e_it ) |
537 | str += e_it.key() + " = " + *e_it + "\n"; | 542 | str += e_it.key() + " = " + *e_it + "\n"; |
538 | } | 543 | } |
539 | cstr = str.utf8(); | 544 | cstr = str.utf8(); |
540 | 545 | ||
541 | int total_length; | 546 | int total_length; |
542 | total_length = f.writeBlock( cstr.data(), cstr.length() ); | 547 | total_length = f.writeBlock( cstr.data(), cstr.length() ); |
543 | if ( total_length != int(cstr.length()) ) { | 548 | if ( total_length != int(cstr.length()) ) { |
544 | QMessageBox::critical( 0, QObject::tr("Out of Space"), | 549 | QMessageBox::critical( 0, QObject::tr("Out of Space"), |
545 | QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); | 550 | QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); |
546 | f.close(); | 551 | f.close(); |
547 | QFile::remove( strNewFile ); | 552 | QFile::remove( strNewFile ); |
548 | return; | 553 | return; |
549 | } | 554 | } |
550 | 555 | ||
551 | f.close(); | 556 | f.close(); |
552 | // now rename the file... | 557 | // now rename the file... |
553 | if ( rename( strNewFile, filename ) < 0 ) { | 558 | if ( rename( strNewFile, filename ) < 0 ) { |
554 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), | 559 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), |
555 | filename.latin1() ); | 560 | filename.latin1() ); |
556 | QFile::remove( strNewFile ); | 561 | QFile::remove( strNewFile ); |
557 | } | 562 | } |
558 | } | 563 | } |
559 | 564 | ||
560 | /*! | 565 | /*! |
561 | Returns whether the KateConfig is in a valid state. | 566 | Returns whether the KateConfig is in a valid state. |
562 | */ | 567 | */ |
563 | bool KateConfig::isValid() const | 568 | bool KateConfig::isValid() const |
564 | { | 569 | { |
565 | return groups.end() != git; | 570 | return groups.end() != git; |
566 | } | 571 | } |
567 | 572 | ||
568 | /*! | 573 | /*! |
569 | \internal | 574 | \internal |
570 | */ | 575 | */ |
571 | void KateConfig::read() | 576 | void KateConfig::read() |
572 | { | 577 | { |
573 | changed = FALSE; | 578 | changed = FALSE; |
574 | 579 | ||
575 | if ( !QFileInfo( filename ).exists() ) { | 580 | if ( !QFileInfo( filename ).exists() ) { |
576 | git = groups.end(); | 581 | git = groups.end(); |
577 | return; | 582 | return; |
578 | } | 583 | } |
579 | 584 | ||
580 | QFile f( filename ); | 585 | QFile f( filename ); |
581 | if ( !f.open( IO_ReadOnly ) ) { | 586 | if ( !f.open( IO_ReadOnly ) ) { |
582 | git = groups.end(); | 587 | git = groups.end(); |
583 | return; | 588 | return; |
584 | } | 589 | } |
585 | 590 | ||
586 | QTextStream s( &f ); | 591 | QTextStream s( &f ); |
587 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 592 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
588 | // The below should work, but doesn't in Qt 2.3.0 | 593 | // The below should work, but doesn't in Qt 2.3.0 |
589 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | 594 | s.setCodec( QTextCodec::codecForMib( 106 ) ); |
590 | #else | 595 | #else |
591 | s.setEncoding( QTextStream::UnicodeUTF8 ); | 596 | s.setEncoding( QTextStream::UnicodeUTF8 ); |
592 | #endif | 597 | #endif |
593 | 598 | ||
594 | QStringList list = QStringList::split('\n', s.read() ); | 599 | QStringList list = QStringList::split('\n', s.read() ); |
595 | f.close(); | 600 | f.close(); |
596 | 601 | ||
597 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 602 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
598 | if ( !parse( *it ) ) { | 603 | if ( !parse( *it ) ) { |
599 | git = groups.end(); | 604 | git = groups.end(); |
600 | return; | 605 | return; |
601 | } | 606 | } |
602 | } | 607 | } |
603 | } | 608 | } |
604 | 609 | ||
605 | /*! | 610 | /*! |
606 | \internal | 611 | \internal |
607 | */ | 612 | */ |
608 | bool KateConfig::parse( const QString &l ) | 613 | bool KateConfig::parse( const QString &l ) |
609 | { | 614 | { |
610 | QString line = l.stripWhiteSpace(); | 615 | QString line = l.stripWhiteSpace(); |
611 | 616 | ||
612 | if ( line [0] == QChar ( '#' )) | 617 | if ( line [0] == QChar ( '#' )) |
613 | return true; // ignore comments | 618 | return true; // ignore comments |
614 | 619 | ||
615 | if ( line[ 0 ] == QChar( '[' ) ) { | 620 | if ( line[ 0 ] == QChar( '[' ) ) { |
616 | QString gname = line; | 621 | QString gname = line; |
617 | gname = gname.remove( 0, 1 ); | 622 | gname = gname.remove( 0, 1 ); |
618 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | 623 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) |
619 | gname = gname.remove( gname.length() - 1, 1 ); | 624 | gname = gname.remove( gname.length() - 1, 1 ); |
620 | git = groups.insert( gname, KateConfigGroup() ); | 625 | git = groups.insert( gname, KateConfigGroup() ); |
621 | } else if ( !line.isEmpty() ) { | 626 | } else if ( !line.isEmpty() ) { |
622 | if ( git == groups.end() ) | 627 | if ( git == groups.end() ) |
623 | return FALSE; | 628 | return FALSE; |
624 | int eq = line.find( '=' ); | 629 | int eq = line.find( '=' ); |
625 | if ( eq == -1 ) | 630 | if ( eq == -1 ) |
626 | return FALSE; | 631 | return FALSE; |
627 | QString key = line.left(eq).stripWhiteSpace(); | 632 | QString key = line.left(eq).stripWhiteSpace(); |
628 | QString value = line.mid(eq+1).stripWhiteSpace(); | 633 | QString value = line.mid(eq+1).stripWhiteSpace(); |
629 | ( *git ).insert( key, value ); | 634 | ( *git ).insert( key, value ); |
630 | } | 635 | } |
631 | return TRUE; | 636 | return TRUE; |
632 | } | 637 | } |
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index 3c9a637..9865c35 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp | |||
@@ -1,52 +1,57 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | tinykate.cpp | 2 | tinykate.cpp |
3 | Tiny KATE mainwindow | 3 | Tiny KATE mainwindow |
4 | ------------------- | 4 | ------------------- |
5 | begin : November 2002 | 5 | begin : November 2002 |
6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | 6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free softwaSre; you can redistribute it and/or modify * | 11 | * This program is free softwaSre; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation. * | 13 | * the Free Software Foundation. * |
14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * | 14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include <qaction.h> | ||
18 | #include <qtoolbutton.h> | ||
19 | #include <qmenubar.h> | ||
20 | #include <qpe/resource.h> | ||
21 | #include <qpe/qpeapplication.h> | ||
22 | 17 | ||
18 | #include "tinykate.h" | ||
19 | |||
20 | #include "katedocument.h" | ||
21 | #include "kglobal.h" | ||
22 | |||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
23 | #include <opie2/ofiledialog.h> | 25 | #include <opie2/ofiledialog.h> |
26 | #include <qpe/resource.h> | ||
27 | #include <qpe/qpeapplication.h> | ||
24 | 28 | ||
25 | #include "tinykate.h" | 29 | /* QT */ |
30 | #include <qaction.h> | ||
31 | #include <qtoolbutton.h> | ||
32 | #include <qmenubar.h> | ||
26 | 33 | ||
27 | #include <katedocument.h> | ||
28 | #include <kglobal.h> | ||
29 | 34 | ||
30 | using namespace Opie::Ui; | 35 | using namespace Opie::Ui; |
31 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 36 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
32 | QMainWindow( parent, name, f ) | 37 | QMainWindow( parent, name, f ) |
33 | { | 38 | { |
34 | shutDown=false; | 39 | shutDown=false; |
35 | nextUnnamed=0; | 40 | nextUnnamed=0; |
36 | currentView=0; | 41 | currentView=0; |
37 | viewCount=0; | 42 | viewCount=0; |
38 | setCaption(tr("TinyKATE")); | 43 | setCaption(tr("TinyKATE")); |
39 | KGlobal::setAppName("TinyKATE"); | 44 | KGlobal::setAppName("TinyKATE"); |
40 | 45 | ||
41 | QMenuBar *mb = new QMenuBar( this ); | 46 | QMenuBar *mb = new QMenuBar( this ); |
42 | mb->setMargin( 0 ); | 47 | mb->setMargin( 0 ); |
43 | 48 | ||
44 | tabwidget=new OTabWidget(this); | 49 | tabwidget=new OTabWidget(this); |
45 | setCentralWidget(tabwidget); | 50 | setCentralWidget(tabwidget); |
46 | connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*))); | 51 | connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*))); |
47 | 52 | ||
48 | //FILE ACTIONS | 53 | //FILE ACTIONS |
49 | QPopupMenu *popup = new QPopupMenu( this ); | 54 | QPopupMenu *popup = new QPopupMenu( this ); |
50 | 55 | ||
51 | // Action for creating a new document | 56 | // Action for creating a new document |
52 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 57 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
@@ -131,78 +136,78 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
131 | mb->insertItem( editUndo ); | 136 | mb->insertItem( editUndo ); |
132 | mb->insertItem( editRedo ); | 137 | mb->insertItem( editRedo ); |
133 | 138 | ||
134 | 139 | ||
135 | //Highlight management | 140 | //Highlight management |
136 | hlmenu=new QPopupMenu(this); | 141 | hlmenu=new QPopupMenu(this); |
137 | HlManager *hlm=HlManager::self(); | 142 | HlManager *hlm=HlManager::self(); |
138 | for (int i=0;i<hlm->highlights();i++) | 143 | for (int i=0;i<hlm->highlights();i++) |
139 | { | 144 | { |
140 | hlmenu->insertItem(hlm->hlName(i),i); | 145 | hlmenu->insertItem(hlm->hlName(i),i); |
141 | } | 146 | } |
142 | popup->insertItem(tr("Highlighting"),hlmenu); | 147 | popup->insertItem(tr("Highlighting"),hlmenu); |
143 | 148 | ||
144 | 149 | ||
145 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); | 150 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); |
146 | utilSettings->addTo( popup); | 151 | utilSettings->addTo( popup); |
147 | 152 | ||
148 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 153 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
149 | else slotNew(); | 154 | else slotNew(); |
150 | 155 | ||
151 | } | 156 | } |
152 | 157 | ||
153 | TinyKate::~TinyKate( ) | 158 | TinyKate::~TinyKate( ) |
154 | { | 159 | { |
155 | qWarning("TinyKate destructor\n"); | 160 | owarn << "TinyKate destructor\n" << oendl; |
156 | 161 | ||
157 | shutDown=true; | 162 | shutDown=true; |
158 | while (currentView!=0) { | 163 | while (currentView!=0) { |
159 | slotClose(); | 164 | slotClose(); |
160 | } | 165 | } |
161 | 166 | ||
162 | if( KGlobal::config() != 0 ) { | 167 | if( KGlobal::config() != 0 ) { |
163 | qWarning("deleting KateConfig object..\n"); | 168 | owarn << "deleting KateConfig object..\n" << oendl; |
164 | delete KGlobal::config(); | 169 | delete KGlobal::config(); |
165 | } | 170 | } |
166 | } | 171 | } |
167 | 172 | ||
168 | void TinyKate::slotOpen( ) | 173 | void TinyKate::slotOpen( ) |
169 | { | 174 | { |
170 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 175 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
171 | QString::null); | 176 | QString::null); |
172 | if (!filename.isEmpty()) { | 177 | if (!filename.isEmpty()) { |
173 | open(filename); | 178 | open(filename); |
174 | } | 179 | } |
175 | } | 180 | } |
176 | 181 | ||
177 | void TinyKate::open(const QString & filename) | 182 | void TinyKate::open(const QString & filename) |
178 | { | 183 | { |
179 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 184 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
180 | KTextEditor::View *kv; | 185 | KTextEditor::View *kv; |
181 | QFileInfo fi(filename); | 186 | QFileInfo fi(filename); |
182 | QString filenamed = fi.fileName(); | 187 | QString filenamed = fi.fileName(); |
183 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); | 188 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); |
184 | qDebug(filename); | 189 | odebug << filename << oendl; |
185 | 190 | ||
186 | kd->setDocName( filenamed); | 191 | kd->setDocName( filenamed); |
187 | kd->open( filename ); | 192 | kd->open( filename ); |
188 | viewCount++; | 193 | viewCount++; |
189 | } | 194 | } |
190 | 195 | ||
191 | void TinyKate::setDocument(const QString& fileref) | 196 | void TinyKate::setDocument(const QString& fileref) |
192 | { | 197 | { |
193 | open( fileref ); | 198 | open( fileref ); |
194 | } | 199 | } |
195 | 200 | ||
196 | void TinyKate::slotCurrentChanged( QWidget * view) | 201 | void TinyKate::slotCurrentChanged( QWidget * view) |
197 | { | 202 | { |
198 | if (currentView) { | 203 | if (currentView) { |
199 | 204 | ||
200 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 205 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
201 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 206 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
202 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 207 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
203 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 208 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
204 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 209 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
205 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 210 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
206 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 211 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
207 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 212 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
208 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 213 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
@@ -228,52 +233,52 @@ void TinyKate::slotNew( ) | |||
228 | KTextEditor::View *kv; | 233 | KTextEditor::View *kv; |
229 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), | 234 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), |
230 | "tinykate/tinykate", | 235 | "tinykate/tinykate", |
231 | tr("Unnamed %1").arg(nextUnnamed++)); | 236 | tr("Unnamed %1").arg(nextUnnamed++)); |
232 | viewCount++; | 237 | viewCount++; |
233 | } | 238 | } |
234 | 239 | ||
235 | void TinyKate::slotClose( ) | 240 | void TinyKate::slotClose( ) |
236 | { | 241 | { |
237 | if (currentView==0) return; | 242 | if (currentView==0) return; |
238 | KTextEditor::View *dv=currentView; | 243 | KTextEditor::View *dv=currentView; |
239 | currentView=0; | 244 | currentView=0; |
240 | tabwidget->removePage(dv); | 245 | tabwidget->removePage(dv); |
241 | delete dv->document(); | 246 | delete dv->document(); |
242 | viewCount--; | 247 | viewCount--; |
243 | if ((!viewCount) && (!shutDown)) slotNew(); | 248 | if ((!viewCount) && (!shutDown)) slotNew(); |
244 | } | 249 | } |
245 | 250 | ||
246 | void TinyKate::slotSave() { | 251 | void TinyKate::slotSave() { |
247 | // feel free to make this how you want | 252 | // feel free to make this how you want |
248 | if (currentView==0) return; | 253 | if (currentView==0) return; |
249 | 254 | ||
250 | // KateView *kv = (KateView*) currentView; | 255 | // KateView *kv = (KateView*) currentView; |
251 | KateDocument *kd = (KateDocument*) currentView->document(); | 256 | KateDocument *kd = (KateDocument*) currentView->document(); |
252 | // qDebug("saving file "+kd->docName()); | 257 | // odebug << "saving file "+kd->docName() << oendl; |
253 | if( kd->docName().isEmpty()) | 258 | if( kd->docName().isEmpty()) |
254 | slotSaveAs(); | 259 | slotSaveAs(); |
255 | else | 260 | else |
256 | kd->saveFile(); | 261 | kd->saveFile(); |
257 | // kv->save(); | 262 | // kv->save(); |
258 | // kd->saveFile(); | 263 | // kd->saveFile(); |
259 | } | 264 | } |
260 | 265 | ||
261 | void TinyKate::slotSaveAs() { | 266 | void TinyKate::slotSaveAs() { |
262 | if (currentView==0) return; | 267 | if (currentView==0) return; |
263 | KateDocument *kd = (KateDocument*) currentView->document(); | 268 | KateDocument *kd = (KateDocument*) currentView->document(); |
264 | 269 | ||
265 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, | 270 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
266 | QString::null); | 271 | QString::null); |
267 | if (!filename.isEmpty()) { | 272 | if (!filename.isEmpty()) { |
268 | qDebug("saving file "+filename); | 273 | odebug << "saving file "+filename << oendl; |
269 | QFileInfo fi(filename); | 274 | QFileInfo fi(filename); |
270 | QString filenamed = fi.fileName(); | 275 | QString filenamed = fi.fileName(); |
271 | kd->setDocFile( filename); | 276 | kd->setDocFile( filename); |
272 | kd->setDocName( filenamed); | 277 | kd->setDocName( filenamed); |
273 | kd->saveFile(); | 278 | kd->saveFile(); |
274 | // KTextEditor::View *dv = currentView; | 279 | // KTextEditor::View *dv = currentView; |
275 | // tabwidget->changeTab( dv, filenamed); | 280 | // tabwidget->changeTab( dv, filenamed); |
276 | // need to change tab label here | 281 | // need to change tab label here |
277 | } | 282 | } |
278 | 283 | ||
279 | } | 284 | } |