00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "layout.h"
00022
00023 namespace SaX {
00024
00025
00026
00027 SaXManipulateLayout::SaXManipulateLayout (SaXImport* layout,SaXImport* card ) {
00028
00032
00033 if ((! layout) || (! card)) {
00034 excNullPointerArgument ();
00035 qError (errorString(),EXC_NULLPOINTERARGUMENT);
00036 return;
00037 }
00038 if ( layout->getSectionID() != SAX_LAYOUT ) {
00039 excLayoutImportBindFailed ( layout->getSectionID() );
00040 qError (errorString(),EXC_LAYOUTIMPORTBINDFAILED);
00041 return;
00042 }
00043 if ( card->getSectionID() != SAX_CARD ) {
00044 excCardImportBindFailed ( card->getSectionID() );
00045 qError (errorString(),EXC_CARDIMPORTBINDFAILED);
00046 return;
00047 }
00048 mLayout = layout;
00049 mCard = card;
00050 mLayout -> setID ( 0 );
00051 mCard -> setID ( 0 );
00052 }
00053
00054
00055
00056
00057 void SaXManipulateLayout::setXOrgMultiheadMode ( int mode ) {
00058
00062
00063 switch (mode) {
00064 case SAX_XINERAMA:
00065 mLayout -> setItem ("Clone","off");
00066 mLayout -> setItem ("Xinerama","on");
00067 break;
00068 case SAX_TRADITIONAL:
00069 mLayout -> setItem ("Clone","off");
00070 mLayout -> setItem ("Xinerama","off");
00071 break;
00072 case SAX_CLONE:
00073 mLayout -> setItem ("Clone","on");
00074 mLayout -> setItem ("Xinerama","on");
00075 break;
00076 default:
00077 excInvalidArgument (mode);
00078 qError (errorString(),EXC_INVALIDARGUMENT);
00079 break;
00080 }
00081 }
00082
00083
00084
00085
00086 bool SaXManipulateLayout::setXOrgLayout (
00087 int screen, int left, int right, int top, int bottom
00088 ) {
00089
00094
00095 SaXManipulateCard cardData (mCard);
00096 if (! cardData.selectCard (screen)) {
00097 return false;
00098 }
00099 QString leftID ("<none>");
00100 QString rightID ("<none>");
00101 QString topID ("<none>");
00102 QString bottomID ("<none>");
00103 if (left >= 0) {
00104 leftID.sprintf ("Screen[%d]",left);
00105 }
00106 if (right >= 0) {
00107 rightID.sprintf ("Screen[%d]",right);
00108 }
00109 if (top >= 0) {
00110 topID.sprintf ("Screen[%d]",top);
00111 }
00112 if (bottom >= 0) {
00113 bottomID.sprintf ("Screen[%d]",bottom);
00114 }
00115 QString screenID; screenID.sprintf ("%d",screen);
00116 mLayout -> setItem (
00117 QString("Screen:Screen["+ screenID + "]"),
00118 QString(leftID + " " + rightID + " " + topID + " " + bottomID)
00119 );
00120 return true;
00121 }
00122
00123
00124
00125
00126 int SaXManipulateLayout::getMultiheadMode ( void ) {
00127
00133
00134 QString clone = mLayout -> getItem ("Clone");
00135 QString xrama = mLayout -> getItem ("Xinerama");
00136
00137
00138
00139 if (mCard->getCount() == 1) {
00140 SaXManipulateCard cardData (mCard);
00141 for (int card=0;card<mCard->getCount();card++) {
00142 cardData.selectCard (card);
00143 QDict<QString> options = cardData.getOptions();
00144 if (options["TwinView"]) {
00145 if (*options["TwinView"] == "Clone") {
00146 return SAX_TWINVIEW_CLONE;
00147 } else {
00148 return SAX_TWINVIEW;
00149 }
00150 }
00151
00152
00153
00154 }
00155 }
00156
00157
00158
00159 if ((clone == "off") && (xrama == "off") && (mCard->getCount() > 1)) {
00160 return SAX_TRADITIONAL;
00161 }
00162
00163
00164
00165 if ((clone == "off") && (xrama == "off")) {
00166 return SAX_SINGLE_HEAD;
00167 }
00168
00169
00170
00171 if (clone == "on") {
00172 return SAX_CLONE;
00173 }
00174
00175
00176
00177 if (xrama == "on") {
00178 return SAX_XINERAMA;
00179 }
00180 return SAX_UNKNOWN_MODE;
00181 }
00182
00183
00184
00185
00186 QList<QString> SaXManipulateLayout::getXOrgLayout ( int screen ) {
00187
00192
00193 SaXManipulateCard cardData (mCard);
00194 if (! cardData.selectCard (screen)) {
00195 return QList<QString> ();
00196 }
00197 QString idString; idString.sprintf ("%d",screen);
00198 QString layout = mLayout -> getItem (
00199 QString("Screen:Screen["+ idString + "]")
00200 );
00201 if (layout.isEmpty()) {
00202 excGetScreenLayoutFailed (screen);
00203 qError (errorString(),EXC_GETSCREENLAYOUTFAILED);
00204 return QList<QString> ();
00205 }
00206 QList<QString> layoutList;
00207 QStringList positions = QStringList::split ( " ", layout );
00208 for ( QStringList::Iterator
00209 in = positions.begin(); in != positions.end(); ++in
00210 ) {
00211 QString* pos = new QString (*in);
00212 layoutList.append (pos);
00213 }
00214 return layoutList;
00215 }
00216
00217
00218
00219
00220 QList<QString> SaXManipulateLayout::getInputLayout ( void ) {
00221
00224
00225 QString layout = mLayout -> getItem ("InputDevice");
00226 if (layout.isEmpty()) {
00227 excGetInputLayoutFailed ();
00228 qError (errorString(),EXC_GETINPUTLAYOUTFAILED);
00229 return QList<QString> ();
00230 }
00231 QList<QString> inputList;
00232 QStringList tokens = QStringList::split ( ",", layout );
00233 for ( QStringList::Iterator
00234 in = tokens.begin(); in != tokens.end(); ++in
00235 ) {
00236 QString* item = new QString (*in);
00237 QRegExp identifier ("\\[(.+)\\]");
00238 int pos = identifier.search (*item);
00239 if (pos >= 0) {
00240 inputList.append (
00241 new QString (identifier.cap(1))
00242 );
00243 }
00244 }
00245 return inputList;
00246 }
00247
00248
00249
00250
00251 void SaXManipulateLayout::addInputLayout ( int id ) {
00252
00255
00256 QString mouseID;
00257 QString layout = mLayout -> getItem ("InputDevice");
00258 QTextOStream (&mouseID) << ",Mouse[" << id << "]";
00259 layout.append (mouseID);
00260 layout.replace (QRegExp("^,"),"");
00261 mLayout -> setItem (
00262 "InputDevice",layout
00263 );
00264 }
00265
00266
00267
00268
00269 void SaXManipulateLayout::removeInputLayout ( int id ) {
00270
00273
00274 QString mouseID;
00275 QString result ("");
00276 QString layout = mLayout -> getItem ("InputDevice");
00277 QTextOStream (&mouseID) << "Mouse[" << id << "]";
00278 QStringList tokens = QStringList::split ( ",", layout );
00279 for ( QStringList::Iterator
00280 in = tokens.begin(); in != tokens.end(); ++in
00281 ) {
00282 QString item = *in;
00283 if ( item != mouseID ) {
00284 result.append (","+item);
00285 }
00286 }
00287 result.replace (QRegExp("^,"),"");
00288 mLayout -> setItem (
00289 "InputDevice",result
00290 );
00291 }
00292 }