~ubuntu-branches/ubuntu/precise/kgrubeditor/precise

« back to all changes in this revision

Viewing changes to src/core/data.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-08-12 16:12:09 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080812161209-uiv9urtsluly7rtc
Tags: 0.8-0ubuntu1
* New upstream release
* Remove debian/cdbs and use kde4.mk from cdbs instead
* Add manpage

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2008 by Konstantinos Smanis                             *
3
 
 *   kon.smanis@gmail.com                                                  *
4
 
 *                                                                         *
5
 
 *   This file is part of KGRUBEditor.                                     *
6
 
 *                                                                         *
7
 
 *   This program is free software; you can redistribute it and/or modify  *
8
 
 *   it under the terms of the GNU General Public License as published by  *
9
 
 *   the Free Software Foundation; either version 2 of the License, or     *
10
 
 *   (at your option) any later version.                                   *
11
 
 *                                                                         *
12
 
 *   This program is distributed in the hope that it will be useful,       *
13
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 
 *   GNU General Public License for more details.                          *
16
 
 *                                                                         *
17
 
 *   You should have received a copy of the GNU General Public License     *
18
 
 *   along with this program; if not, write to the                         *
19
 
 *   Free Software Foundation, Inc.,                                       *
20
 
 *   51 Franklin Street, Fifth Floor                                       *
21
 
 *   Boston, MA  02111-1307, USA.                                          *
22
 
 ***************************************************************************/
23
 
 
24
 
//Own
25
 
#include "data.h"
26
 
 
27
 
//Qt
28
 
#include <qregexp.h>
29
 
 
30
 
//KDE
31
 
#include <klocale.h>
32
 
 
33
 
namespace GRUB
34
 
{
35
 
        namespace ComplexCommand
36
 
        {
37
 
                //
38
 
                //Map
39
 
                //
40
 
                Map::Map()
41
 
                {
42
 
                        clear();
43
 
                }
44
 
                Map::Map( const QString toDrive, const QString fromDrive )
45
 
                {
46
 
                        clear();
47
 
                        m_toDrive = toDrive;
48
 
                        m_fromDrive = fromDrive;
49
 
                }
50
 
                Map::Map( const QString map )
51
 
                {
52
 
                        clear();
53
 
                        resolve( map );
54
 
                }
55
 
                void Map::clear()
56
 
                {
57
 
                        m_toDrive.clear();
58
 
                        m_fromDrive.clear();
59
 
                }
60
 
                void Map::resolve( const QString map )
61
 
                {
62
 
                        m_toDrive = map.section( QRegExp( "\\s+" ), 0, 0 );
63
 
                        m_fromDrive = map.section( QRegExp( "\\s+" ), 1 );
64
 
                }
65
 
                const QString Map::result() const
66
 
                {
67
 
                        return i18n( "%1 is mapped to %2", m_fromDrive, m_toDrive );
68
 
                }
69
 
 
70
 
                //
71
 
                //Color
72
 
                //
73
 
                QMap<int, QString> Color::m_colorMap = Color::mappedColors();
74
 
                Color::Color()
75
 
                {
76
 
                        clear();
77
 
                }
78
 
                Color::Color( const QString color )
79
 
                {
80
 
                        clear();
81
 
                        resolve( color );
82
 
                }
83
 
                void Color::clear()
84
 
                {
85
 
                        m_blinkNormal = false;
86
 
                        m_normalBackground.clear();
87
 
                        m_normalForeground.clear();
88
 
                        m_blinkHighlighted = false;
89
 
                        m_highlightedBackground.clear();
90
 
                        m_highlightedForeground.clear();
91
 
                }
92
 
                void Color::resolve( QString color )
93
 
                {
94
 
                        m_blinkNormal = color.section( QRegExp( "\\s+" ), 0, 0 ).section( "/", 0, 0 ).startsWith( "blink-" );
95
 
                        m_normalBackground = color.section( QRegExp( "\\s+" ), 0, 0 ).section( "/", 1 );
96
 
                        m_normalForeground = color.section( QRegExp( "\\s+" ), 0, 0 ).section( "/", 0, 0 ).remove( "blink-" );
97
 
                        m_blinkHighlighted = color.section( QRegExp( "\\s+" ), 1 ).section( "/", 0, 0 ).startsWith( "blink-" );
98
 
                        m_highlightedBackground = color.section( QRegExp( "\\s+" ), 1 ).section( "/", 1 );
99
 
                        m_highlightedForeground = color.section( QRegExp( "\\s+" ), 1 ).section( "/", 0, 0 ).remove( "blink-" );
100
 
                }
101
 
                const QString Color::result() const
102
 
                {
103
 
                        QString result = 
104
 
                        ( m_blinkNormal ? "blink-" : QString() ) + m_normalForeground + ( normalIsEnabled() ? "/" : QString() ) + m_normalBackground 
105
 
                        + " " 
106
 
                        + ( m_blinkHighlighted ? "blink-" : QString() ) + m_highlightedForeground + ( highlightedIsEnabled() ? "/" : QString() ) + m_highlightedBackground;
107
 
                        return result;
108
 
                }
109
 
                const QMap<int, QString> Color::mappedColors()
110
 
                {
111
 
                        QMap<int, QString> colorMap;
112
 
                        colorMap[0] = "black";
113
 
                        colorMap[1] = "blue";
114
 
                        colorMap[2] = "green";
115
 
                        colorMap[3] = "cyan";
116
 
                        colorMap[4] = "red";
117
 
                        colorMap[5] = "magenta";
118
 
                        colorMap[6] = "brown";
119
 
                        colorMap[7] = "light-gray";
120
 
 
121
 
                        colorMap[8] = "dark-gray";
122
 
                        colorMap[9] = "light-blue";
123
 
                        colorMap[10] = "light-green";
124
 
                        colorMap[11] = "light-cyan";
125
 
                        colorMap[12] = "light-red";
126
 
                        colorMap[13] = "light-magenta";
127
 
                        colorMap[14] = "yellow";
128
 
                        colorMap[15] = "white";
129
 
                        return colorMap;
130
 
                }
131
 
                const QString Color::previewOptimisedColor( const QString color ) const
132
 
                {
133
 
                        if ( color == "magenta" )
134
 
                                return QString( "darkmagenta" );
135
 
                        else if ( color == "light-magenta" )
136
 
                                return QString( "magenta" );
137
 
                        else if ( color == "light-red" )
138
 
                                return QString( "orangered" );
139
 
                        else
140
 
                                return QString( color ).remove( "-" );
141
 
                }
142
 
 
143
 
                //
144
 
                //Password
145
 
                //
146
 
                Password::Password()
147
 
                {
148
 
                        clear();
149
 
                }
150
 
                Password::Password( const bool md5crypted, const QString password, const QString configFile )
151
 
                {
152
 
                        clear();
153
 
                        m_md5crypted = md5crypted;
154
 
                        m_password = password;
155
 
                        m_configFile = configFile;                      
156
 
                }
157
 
                Password::Password( const QString password )
158
 
                {
159
 
                        clear();
160
 
                        resolve( password );
161
 
                }
162
 
                void Password::clear()
163
 
                {
164
 
                        m_md5crypted = false;
165
 
                        m_password.clear();
166
 
                        m_configFile.clear();
167
 
                }
168
 
                void Password::resolve( QString password )
169
 
                {
170
 
                        if ( password.startsWith( "--md5" ) )
171
 
                        {
172
 
                                m_md5crypted = true;
173
 
                                m_password = password.section( QRegExp( "\\s+" ), 1, 1 );
174
 
                                m_configFile = password.section( QRegExp( "\\s+" ), 2, 2 );
175
 
                        }
176
 
                        else
177
 
                        {
178
 
                                m_md5crypted = false;
179
 
                                m_password = password.section( QRegExp( "\\s+" ), 0, 0 );
180
 
                                m_configFile = password.section( QRegExp( "\\s+" ), 1, 1 );
181
 
                        }
182
 
                }
183
 
                const QString Password::result() const
184
 
                {
185
 
                        return QString( ( m_md5crypted ? "--md5 " : QString() ) + m_password + ( !m_configFile.isEmpty() ? " " + m_configFile : QString() ) );
186
 
                }
187
 
 
188
 
                //
189
 
                //Kernel
190
 
                //
191
 
                Kernel::Kernel()
192
 
                {
193
 
                        clear();
194
 
                }
195
 
                Kernel::Kernel( const QString kernel )
196
 
                {
197
 
                        clear();
198
 
                        resolve( kernel );
199
 
                }
200
 
                Kernel::Kernel( const QString kernel, const QString arguments )
201
 
                {
202
 
                        m_kernel = kernel;
203
 
                        m_arguments = arguments;
204
 
                }
205
 
                void Kernel::clear()
206
 
                {
207
 
                        m_kernel.clear();
208
 
                        m_arguments.clear();
209
 
                }
210
 
                void Kernel::resolve( QString kernel )
211
 
                {
212
 
                        m_kernel = kernel.section( QRegExp( "\\s+" ), 0, 0 );
213
 
                        m_arguments = kernel.section( QRegExp( "\\s+" ), 1 );
214
 
                }
215
 
                const QString Kernel::result() const
216
 
                {
217
 
                        return QString( m_kernel + " " + m_arguments );
218
 
                }
219
 
        }
220
 
 
221
 
        namespace ConfigFile
222
 
        {
223
 
                //
224
 
                //Entry
225
 
                //
226
 
                Entry::Entry()
227
 
                {
228
 
                        clear();
229
 
                }
230
 
                void Entry::clear()
231
 
                {
232
 
                        m_title.clear();
233
 
                        m_lock = false;
234
 
                        m_password.clear();
235
 
                        m_root.clear();
236
 
                        m_kernel.clear();
237
 
                        m_initrd.clear();
238
 
                        m_color.clear();
239
 
                        m_maps.clear();
240
 
                        m_chainLoader.clear();
241
 
                        m_saveDefault = false;
242
 
                        m_makeActive = false;
243
 
                }
244
 
                
245
 
                //
246
 
                //Settings
247
 
                //
248
 
                Settings::Settings()
249
 
                {
250
 
                        clear();
251
 
                }
252
 
                void Settings::clear()
253
 
                {
254
 
                        m_splashImage.clear();
255
 
                        m_gfxMenu.clear();
256
 
                        m_timeout = -1;
257
 
                        m_default = -1;
258
 
                        m_fallback = -1;
259
 
                        m_hiddenMenu = false;
260
 
                        m_maps.clear();
261
 
                        m_color.clear();
262
 
                        m_password.clear();
263
 
 
264
 
                        m_automagic.clear();
265
 
                }
266
 
        }
267
 
 
268
 
        namespace Misc
269
 
        {
270
 
                //
271
 
                //Device
272
 
                //
273
 
                Device::Device()
274
 
                {
275
 
                        clear();
276
 
                }
277
 
                Device::Device( const QString device, const QString partition, const QString mountpoint )
278
 
                {
279
 
                        clear();
280
 
                        m_device = device;
281
 
                        m_partition = partition;
282
 
                        m_mountPoint = mountpoint;
283
 
                }
284
 
                void Device::clear()
285
 
                {
286
 
                        m_device.clear();
287
 
                        m_partition.clear();
288
 
                        m_grubDevice.clear();
289
 
                        m_grubPartition.clear();
290
 
                        m_mountPoint.clear();
291
 
                        m_uuid.clear();
292
 
                }
293
 
                //
294
 
                //Automagic
295
 
                //
296
 
                Automagic::Automagic()
297
 
                {
298
 
                        clear();
299
 
                }
300
 
                void Automagic::clear()
301
 
                {
302
 
                        m_comments.clear();
303
 
                        m_firstEntry = -1;
304
 
                        m_lastEntry = -1;
305
 
                }
306
 
        }
307
 
}