Main Page | Class List | File List | Class Members | File Members | Related Pages

configuration.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Bojan D.                                        *
00003  *   bojan_d@users.sourceforge.net                                         *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00031 #include <kapplication.h>       // for 'kapp'
00032 #include <kconfig.h>            // for KConfig
00033 #include <klocale.h>
00034 
00035 #include "configuration.h"
00036 
00037 // set up the defaults
00038 const DefaultConfig Configuration::Default = 
00039 {
00040         { FullScreen, 4500, -1, 100, 30, ScalePercent, true },  // the capture defaults
00041         { "", "", "" },                                                 // the file defaults
00042         { true, false, true, "", 21, "", "", "" },      // the FTP defaults
00043         { false, "" },                                                  // the Log defaults
00044         { false, false, Qt::AlignLeft | Qt::AlignTop, 0, 0, "", Qt::black, QFont() }, // the caption defaults
00045         { false, 8080, QStringList() },                 // the WWW settings
00046 };
00047         
00048 Configuration::Configuration()
00049 {
00050         read(); // read the settings or set them to the default values
00051 }
00052 
00053 Configuration::~Configuration()
00054 {
00055 }
00056 
00057 void Configuration::read() 
00058 {
00059     KConfig *conf = kapp->config();
00060     
00061         // read capture options
00062     conf->setGroup("Capture");
00063         Capture.CaptureMode = conf->readNumEntry("capture_mode", Configuration::Default.Capture.CaptureMode);
00064         Capture.CaptureDelay = conf->readNumEntry("delay", Configuration::Default.Capture.CaptureDelay);
00065         Capture.PictureQuality = conf->readNumEntry("quality", Configuration::Default.Capture.PictureQuality);
00066         Capture.ScaleMode = conf->readNumEntry("scale_mode", Configuration::Default.Capture.ScaleMode);
00067         Capture.ScaleMain = conf->readNumEntry("scale_main", Configuration::Default.Capture.ScaleMain);
00068         Capture.ScaleThumb = conf->readNumEntry("scale_thumb", Configuration::Default.Capture.ScaleThumb);
00069         Capture.IncludeWD = conf->readBoolEntry("include_wd", Configuration::Default.Capture.IncludeWD);
00070     
00071         // read path options
00072     conf->setGroup("Paths");
00073         File.PathMain = conf->readEntry("main", Configuration::Default.File.PathMain);
00074         File.PathThumb = conf->readEntry("thumb", Configuration::Default.File.PathThumb);
00075         File.PathOffline = conf->readEntry("offline", Configuration::Default.File.PathOffline);
00076         
00077         // read FTP options
00078     conf->setGroup("FTP");
00079         Ftp.UseFtp = conf->readBoolEntry("use_ftp", Configuration::Default.Ftp.UseFtp);
00080         Ftp.UseThumb = conf->readBoolEntry("use_thumb", Configuration::Default.Ftp.UseThumb);
00081         Ftp.UseOffline = conf->readBoolEntry("use_offline", Configuration::Default.Ftp.UseOffline);
00082         Ftp.Host = conf->readEntry("host", Configuration::Default.Ftp.Host);
00083         Ftp.Port = conf->readNumEntry("port", Configuration::Default.Ftp.Port);
00084         Ftp.User = conf->readEntry("user", Configuration::Default.Ftp.User);
00085         Ftp.TransferPath = conf->readEntry("path", Configuration::Default.Ftp.TransferPath);
00086 
00087         // read Log options
00088     conf->setGroup("Log");
00089         Log.Path = conf->readEntry("path", Configuration::Default.Log.Path);
00090         Log.UseLog = conf->readBoolEntry("use_log", Configuration::Default.Log.UseLog);
00091                 
00092         // read Caption options
00093     conf->setGroup("Caption");
00094         Caption.UseCaption = conf->readBoolEntry("use_caption", Configuration::Default.Caption.UseCaption);
00095         Caption.CustomPos = conf->readBoolEntry("custom_position", Configuration::Default.Caption.CustomPos);
00096         Caption.Position = conf->readNumEntry("position", Configuration::Default.Caption.Position);
00097         Caption.PositionX = conf->readNumEntry("x", Configuration::Default.Caption.PositionX);
00098         Caption.PositionY = conf->readNumEntry("y", Configuration::Default.Caption.PositionY);
00099         Caption.Text = conf->readEntry("text", Configuration::Default.Caption.Text);
00100         Caption.Font = conf->readFontEntry("font", &(Configuration::Default.Caption.Font));
00101         Caption.Color = conf->readColorEntry("color", &(Configuration::Default.Caption.Color));
00102         
00103         // read WWW options
00104     conf->setGroup("WWW");
00105         WWW.UseWWW = conf->readBoolEntry("use_www", Configuration::Default.WWW.UseWWW);
00106         WWW.Port = conf->readNumEntry("port", Configuration::Default.WWW.Port);
00107         WWW.Files = conf->readListEntry("files"); 
00108         
00109 }
00110 
00111 void Configuration::write() const 
00112 {
00113     KConfig *conf=kapp->config();
00114     
00115         // write capture options
00116     conf->setGroup("Capture");
00117         conf->writeEntry("capture_mode", Capture.CaptureMode);
00118         conf->writeEntry("delay", Capture.CaptureDelay);
00119         conf->writeEntry("quality", Capture.PictureQuality);
00120         conf->writeEntry("scale_mode", Capture.ScaleMode);
00121         conf->writeEntry("scale_main", Capture.ScaleMain);
00122         conf->writeEntry("scale_thumb", Capture.ScaleThumb);
00123         conf->writeEntry("include_wd", Capture.IncludeWD);
00124         
00125         // write path options
00126     conf->setGroup("Paths");
00127         conf->writeEntry("main", File.PathMain);
00128         conf->writeEntry("thumb", File.PathThumb);
00129         conf->writeEntry("offline", File.PathOffline);
00130         
00131         // write FTP options
00132     conf->setGroup("FTP");
00133         conf->writeEntry("use_ftp", Ftp.UseFtp);
00134         conf->writeEntry("use_thumb", Ftp.UseThumb);
00135         conf->writeEntry("use_offline", Ftp.UseOffline);
00136         conf->writeEntry("host", Ftp.Host);
00137         conf->writeEntry("port", Ftp.Port);
00138         conf->writeEntry("user", Ftp.User);
00139         conf->writeEntry("path", Ftp.TransferPath);
00140         
00141         // write Log options
00142     conf->setGroup("Log");
00143         conf->writeEntry("path", Log.Path);
00144         conf->writeEntry("use_log", Log.UseLog);
00145                 
00146         // write Caption options
00147     conf->setGroup("Caption");
00148         conf->writeEntry("use_caption", Caption.UseCaption);
00149         conf->writeEntry("custom_position", Caption.CustomPos);
00150         conf->writeEntry("position", Caption.Position);
00151         conf->writeEntry("x", Caption.PositionX);
00152         conf->writeEntry("y", Caption.PositionY);
00153         conf->writeEntry("text", Caption.Text);
00154         conf->writeEntry("font", Caption.Font);
00155         conf->writeEntry("color", Caption.Color);
00156         
00157         // write WWW options
00158     conf->setGroup("WWW");
00159         conf->writeEntry("use_www", WWW.UseWWW);
00160         conf->writeEntry("port", WWW.Port);
00161         conf->writeEntry("files", WWW.Files);
00162 
00163         conf->sync();   
00164 }
00165 
00166 // validates if required fields are empty
00167 bool Configuration::validate(QString& error)
00168 {
00169         if(Ftp.UseFtp)
00170         {
00171                 if(File.PathMain.isEmpty())
00172                 { 
00173                         error = i18n("Invalid path information.");
00174                         return false;
00175                 }
00176                 else if((Ftp.User.isEmpty()) || (Ftp.Host.isEmpty())) 
00177                 {
00178                         error = i18n("Invalid FTP information.");
00179                         return false;
00180                 }
00181         }
00182         
00183         if(WWW.UseWWW)
00184         {
00185                 if(WWW.Port < 0) 
00186                 {
00187                         error = i18n("Invalid WWW server port.");
00188                         return false;
00189                 }
00190         }
00191         
00192         return true;
00193 }
00194 
00195 Configuration& Config() 
00196 {
00197     static Configuration conf;
00198     return conf;
00199 }
00200 
00201 

Generated on Mon Sep 5 12:52:33 2005 for kwebsnap.kdevelop by  doxygen 1.3.9.1