|
libsax 7.2
|
00001 /************** 00002 FILE : export.cpp 00003 *************** 00004 PROJECT : SaX2 - library interface 00005 : 00006 AUTHOR : Marcus Schäfer <ms@suse.de> 00007 : 00008 BELONGS TO : SaX2 - SuSE advanced X11 configuration 00009 : 00010 : 00011 DESCRIPTION : native C++ class library to access SaX2 00012 : functionality. Easy to use interface for 00013 : //.../ 00014 : - importing/exporting X11 configurations 00015 : - modifying/creating X11 configurations 00016 : --- 00017 : 00018 : 00019 STATUS : Status: Development 00020 **************/ 00021 #include "export.h" 00022 00023 namespace SaX { 00024 //==================================== 00025 // Constructor... 00026 //------------------------------------ 00027 SaXExport::SaXExport (SaXImport* import, SaXException* to) { 00028 // .../ 00032 // ---- 00033 if (to) { 00034 mTo = to; 00035 } 00036 switch (import->getSectionID()) { 00037 case SAX_CARD: 00038 mFile = ISAXCARD; 00039 break; 00040 case SAX_DESKTOP: 00041 mFile = ISAXDESKTOP; 00042 break; 00043 case SAX_POINTERS: 00044 mFile = ISAXINPUT; 00045 break; 00046 case SAX_KEYBOARD: 00047 mFile = ISAXKEYBOARD; 00048 break; 00049 case SAX_LAYOUT: 00050 mFile = ISAXLAYOUT; 00051 break; 00052 case SAX_PATH: 00053 mFile = ISAXPATH; 00054 break; 00055 case SAX_EXTENSIONS: 00056 mFile = ISAXEXTENSIONS; 00057 break; 00058 default: 00059 excExportSectionFailed(); 00060 qError (errorString(),EXC_EXPORTSECTIONFAILED); 00061 if (mTo) { 00062 mTo -> excExportSectionFailed(); 00063 } 00064 break; 00065 } 00066 mHandle = new QFile (mFile); 00067 mImport = import; 00068 } 00069 00070 //==================================== 00071 // doExport... 00072 //------------------------------------ 00073 bool SaXExport::doExport (void) { 00074 // .../ 00077 // ---- 00078 if (! havePrivileges()) { 00079 excPermissionDenied (); 00080 qError (errorString(),EXC_PERMISSIONDENIED); 00081 if (mTo) { 00082 mTo -> excPermissionDenied (); 00083 } 00084 return false; 00085 } 00086 if (! mHandle -> open(QIODevice::WriteOnly)) { 00087 excFileOpenFailed ( errno ); 00088 qError (errorString(),EXC_FILEOPENFAILED); 00089 if (mTo) { 00090 mTo -> excFileOpenFailed ( errno ); 00091 } 00092 return false; 00093 } 00094 if ((flock (mHandle->handle(),LOCK_EX)) != 0) { 00095 excLockSetFailed ( errno ); 00096 qError (errorString(),EXC_LOCKSETFAILED); 00097 if (mTo) { 00098 mTo -> excLockSetFailed ( errno ); 00099 } 00100 mHandle -> close(); 00101 return false; 00102 } 00103 for (int id=0; id < mImport->getCount();id++) { 00104 Q3Dict<QString>* data = mImport->getTablePointer (id); 00105 if ( ! data ) { 00106 excNoStorage(id); 00107 qError (errorString(),EXC_NOSTORAGE); 00108 if (mTo) { 00109 mTo -> excNoStorage(id); 00110 } 00111 continue; 00112 } 00113 Q3DictIterator<QString> it (*data); 00114 for (; it.current(); ++it) { 00115 QString line; 00116 line.sprintf ("%d : %-20s : %s\n", 00117 id,it.currentKey().ascii(),it.current()->ascii() 00118 ); 00119 mHandle -> writeBlock ( 00120 line.ascii(),line.length() 00121 ); 00122 } 00123 } 00124 if ((flock (mHandle->handle(),LOCK_UN)) != 0) { 00125 excLockUnsetFailed ( errno ); 00126 qError (errorString(),EXC_LOCKUNSETFAILED); 00127 if (mTo) { 00128 mTo -> excLockUnsetFailed ( errno ); 00129 } 00130 mHandle -> close(); 00131 return false; 00132 } 00133 mHandle -> close(); 00134 return true; 00135 } 00136 } // end namespace
1.7.3