00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "utility.h"
00010
00011
00012 void CenterWindow(QWidget *window)
00013 {
00014 QDesktopWidget *qdw;
00015 QRect qr;
00016 int width, height;
00017
00018 qdw = new QDesktopWidget();
00019 qr = qdw->screenGeometry(window);
00020 delete qdw;
00021
00022 width = qr.width();
00023 height = qr.height();
00024
00025 window->move(((width - window->width()) / 2),((height - window->height()) / 2));
00026 }
00027
00028
00029 void CenterWindow(QWidget *sourceWindow, QWidget *newWindow)
00030 {
00031 int widthSource,heightSource,width,height,xSource,ySource;
00032
00033
00034
00035 widthSource = sourceWindow->width();
00036 heightSource = sourceWindow->height();
00037
00038 xSource = sourceWindow->x();
00039 ySource = sourceWindow->y();
00040
00041 width = newWindow->width();
00042 height = newWindow->height();
00043
00044 newWindow->move((xSource + ((widthSource - width) / 2)),(ySource + ((heightSource - height) / 2)));
00045 }
00046
00047
00048 bool MountRev()
00049 {
00050 char device[20],path[20];
00051
00052 strcpy(device,RevDevice().ascii());
00053 strcpy(path,RevPathMount().ascii());
00054
00055 if (mount(device,path,"udf",0,"") == 0)
00056 {
00057 struct mntent mnt_entry;
00058 FILE *fp;
00059
00060
00061 mnt_entry.mnt_fsname = device;
00062 mnt_entry.mnt_dir = path;
00063 mnt_entry.mnt_type = (char *) "udf";
00064 mnt_entry.mnt_opts = (char *) "defaults,rw,users,noauto";
00065 mnt_entry.mnt_freq = 0;
00066 mnt_entry.mnt_passno = 0;
00067
00068 fp = setmntent("/etc/mtab","r+");
00069 addmntent(fp,&mnt_entry);
00070 endmntent(fp);
00071
00072 return TRUE;
00073 }
00074 else
00075 {
00076 if (errno == EBUSY)
00077 {
00078 return TRUE;
00079 }
00080 else
00081 {
00082 return FALSE;
00083 }
00084 }
00085 }
00086
00087 void delmntent(FILE *stream, const char *mount_point)
00088 {
00089 FILE *ftemp;
00090
00091
00092 char fsname[80],dir[80],type[10],opts[80];
00093 char freq,passno;
00094
00095 ftemp = tmpfile();
00096
00097
00098 while(!feof(stream))
00099 {
00100 char c;
00101 if ((c = fgetc(stream)) != EOF)
00102 fputc(c,ftemp);
00103 }
00104
00105 fflush(ftemp);
00106 rewind(ftemp);
00107
00108 fclose(stream);
00109 stream = fopen("/etc/mtab","w");
00110
00111
00112 while(!feof(ftemp))
00113 {
00114
00115 fscanf(ftemp,"%s %s %s %s %c %c",fsname,dir,type,opts,&freq,&passno);
00116
00117 if (strcmp(fsname,mount_point) != 0 && strcmp(fsname,"\0") != 0)
00118 {
00119
00120 fprintf(stream,"%s %s %s %s %c %c\n",fsname,dir,type,opts,freq,passno);
00121 printf("%s %s %s %s %c %c\n",fsname,dir,type,opts,freq,passno);
00122 }
00123 strcpy(fsname,"\0");
00124 }
00125 fclose(ftemp);
00126 }
00127
00128 bool UmountRev()
00129 {
00130 char device[20],path[20];
00131
00132 strcpy(device,RevDevice().ascii());
00133 strcpy(path,RevPathMount().ascii());
00134
00135 if (umount(path) == 0)
00136 {
00137 FILE *fp;
00138
00139 fp = setmntent("/etc/mtab","r+");
00140 delmntent(fp,device);
00141 endmntent(fp);
00142
00143 return TRUE;
00144 }
00145 else
00146 {
00147 return FALSE;
00148 }
00149 }
00150
00151 void EjectRev()
00152 {
00153 QProcess proc;
00154 char device[20];
00155
00156 strcpy(device,RevDevice().ascii());
00157
00158 proc.addArgument("eject");
00159 proc.addArgument(device);
00160 proc.start();
00161 }
00162
00163 QString RevPathMount()
00164 {
00165 QSettings settings;
00166 QString value;
00167
00168
00169 value = settings.readEntry("DS4CloneRestore/Current/RevMountPoint","/mnt/rev/");
00170
00171 return value;
00172 }
00173
00174 QString RevDevice()
00175 {
00176 QSettings settings;
00177 QString value;
00178
00179
00180 value = settings.readEntry("DS4CloneRestore/Current/RevDevice","/dev/hdb");
00181
00182 return value;
00183 }
00184
00185
00186 QString HDDevice()
00187 {
00188 QSettings settings;
00189 QString value;
00190
00191
00192 value = settings.readEntry("DS4CloneRestore/Current/HdDevice","hda");
00193
00194 return value;
00195 }
00196
00197 QString SystemSwapPartition()
00198 {
00199 QSettings settings;
00200 QString value;
00201
00202
00203 value = settings.readEntry("DS4CloneRestore/Current/SystemSwapPartition","/dev/sda2");
00204
00205 return value;
00206 }
00207
00208
00209 bool MountServer()
00210 {
00211 FILE *fp;
00212
00213 char fsname[80],dir[80],type[10],opts[80];
00214 char freq,passno;
00215 QString command;
00216 bool mounted;
00217
00218 command = "mount " + ServerAddress() + " " + ServerPathMount() + " -t smbfs -o ro,username=\'" +
00219 ServerUsername() + "\',password=\'" + ServerPassword() + "\'";
00220
00221 system(command.ascii());
00222
00223
00224
00225 fp = setmntent("/etc/mtab","r");
00226
00227 mounted = FALSE;
00228
00229 while(!feof(fp))
00230 {
00231 fscanf(fp,"%s %s %s %s %c %c",fsname,dir,type,opts,&freq,&passno);
00232 if (strcmp(fsname,ServerAddress().ascii()) == 0)
00233 mounted = TRUE;
00234 }
00235
00236 endmntent(fp);
00237
00238 return mounted;
00239 }
00240
00241 bool UmountServer()
00242 {
00243 QString command;
00244
00245 command = "umount " + ServerPathMount();
00246
00247 system(command.ascii());
00248 return TRUE;
00249 }
00250
00251 QString ServerPathMount()
00252 {
00253 QSettings settings;
00254 QString value;
00255
00256
00257 value = settings.readEntry("DS4CloneRestore/Current/ServerMountPoint","/mnt/server/");
00258
00259 return value;
00260 }
00261
00262 QString ServerAddress()
00263 {
00264 QSettings settings;
00265 QString value;
00266
00267
00268 value = settings.readEntry("DS4CloneRestore/Current/ServerAddress","//192.168.3.2/partimage");
00269
00270 return value;
00271 }
00272
00273 QString ServerUsername()
00274 {
00275 QSettings settings;
00276 QString value;
00277
00278
00279 value = settings.readEntry("DS4CloneRestore/Current/ServerUsername","");
00280
00281 return value;
00282 }
00283
00284 QString ServerPassword()
00285 {
00286 QSettings settings;
00287 QString value;
00288
00289
00290 value = settings.readEntry("DS4CloneRestore/Current/ServerPassword","");
00291
00292 return value;
00293 }