00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00031 #include <kapplication.h>
00032 #include <kconfig.h>
00033 #include <klocale.h>
00034
00035 #include "configuration.h"
00036
00037
00038 const DefaultConfig Configuration::Default =
00039 {
00040 { FullScreen, 4500, -1, 100, 30, ScalePercent, true },
00041 { "", "", "" },
00042 { true, false, true, "", 21, "", "", "" },
00043 { false, "" },
00044 { false, false, Qt::AlignLeft | Qt::AlignTop, 0, 0, "", Qt::black, QFont() },
00045 { false, 8080, QStringList() },
00046 };
00047
00048 Configuration::Configuration()
00049 {
00050 read();
00051 }
00052
00053 Configuration::~Configuration()
00054 {
00055 }
00056
00057 void Configuration::read()
00058 {
00059 KConfig *conf = kapp->config();
00060
00061
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
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
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
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
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
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
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
00126 conf->setGroup("Paths");
00127 conf->writeEntry("main", File.PathMain);
00128 conf->writeEntry("thumb", File.PathThumb);
00129 conf->writeEntry("offline", File.PathOffline);
00130
00131
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
00142 conf->setGroup("Log");
00143 conf->writeEntry("path", Log.Path);
00144 conf->writeEntry("use_log", Log.UseLog);
00145
00146
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
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
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