Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

karambaconf.cpp

Go to the documentation of this file.
00001 #include "karambaconf.h"
00002 
00003 /*
00004  *  Constructs a KarambaConf as a child of Karamba with the
00005  *  name 'KarambaConf' .
00006  *
00007  */
00008 KarambaConf::KarambaConf( QWidget* parent, const char* name, bool modal, WFlags fl )
00009     : QDialog( parent, name, modal, fl )
00010 {
00011     loadConfig();
00012     if ( !name ){
00013       setName( "Karamba_conf" );
00014     }
00015     setMinimumSize( QSize( 600, 360 ) );
00016     setMaximumSize( QSize( 600, 360 ) );
00017     setSizeGripEnabled( TRUE );
00018 
00019     QWidget* privateLayoutWidget = new QWidget( this, "Layout1" );
00020     privateLayoutWidget->setGeometry( QRect( 11, 326, 575, 27 ) );
00021     Layout1 = new QHBoxLayout( privateLayoutWidget, 0, 6, "Layout1"); 
00022 
00023     buttonHelp = new QPushButton( privateLayoutWidget, "buttonHelp" );
00024     buttonHelp->setAutoDefault( TRUE );
00025     Layout1->addWidget( buttonHelp );
00026     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00027     Layout1->addItem( spacer );
00028 
00029     buttonOk = new QPushButton( privateLayoutWidget, "buttonOk" );
00030     buttonOk->setAutoDefault( TRUE );
00031     buttonOk->setDefault( TRUE );
00032     Layout1->addWidget( buttonOk );
00033 
00034     buttonCancel = new QPushButton( privateLayoutWidget, "buttonCancel" );
00035     buttonCancel->setAutoDefault( TRUE );
00036     Layout1->addWidget( buttonCancel );
00037 
00038     QWidget* privateLayoutWidget_2 = new QWidget( this, "layout5" );
00039     privateLayoutWidget_2->setGeometry( QRect( 5, 0, 590, 320 ) );
00040     layout5 = new QHBoxLayout( privateLayoutWidget_2, 0, 0, "layout5");
00041 
00042     tabWidget = new QTabWidget( privateLayoutWidget_2, "tabWidget" );
00043     tabWidget->setEnabled( TRUE );
00044     tabWidget->setMinimumSize( QSize( 590, 320 ) );
00045     tabWidget->setMaximumSize( QSize( 590, 320 ) );
00046     tabWidget->setAutoMask( TRUE );
00047 
00048     Widget2 = new QWidget( tabWidget, "Widget2" );
00049     QWidget* privateLayoutWidget_3 = new QWidget( Widget2, "layout3" );
00050     privateLayoutWidget_3->setGeometry( QRect( 10, 10, 570, 280 ) );
00051     layout3 = new QVBoxLayout( privateLayoutWidget_3, 11, 6, "layout3");
00052 
00053     dFolderGroup = new QGroupBox( privateLayoutWidget_3, "dFolderGroup" );
00054     dFolderGroup->setGeometry( QRect( 0, 0, 570, 60 ) );
00055 
00056     dFolder = new QLineEdit( dFolderGroup, "dFolder" );
00057     dFolder->setGeometry( QRect( 20, 20, 250, 22 ) );
00058     dFolder->setText( Dir );
00059 
00060     browse_1 = new QPushButton( dFolderGroup, "browse_1" );
00061     browse_1->setGeometry( QRect( 300, 20, 100, 28 ) );
00062     layout3->addWidget( dFolderGroup );
00063 
00064     dThemeGroup = new QGroupBox( privateLayoutWidget_3, "dThemeGroup" );
00065     dThemeGroup->setGeometry( QRect( 10, 70, 570, 120 ) );
00066 
00067     dTheme = new QLineEdit( dThemeGroup, "dTheme" );
00068     dTheme->setGeometry( QRect( 20, 20, 250, 22 ) );
00069     dTheme->setText( Theme );
00070 
00071     browse_2 = new QPushButton( dThemeGroup, "browse_2" );
00072     browse_2->setGeometry( QRect( 300, 18, 100, 28 ) );
00073     themeLabel = new QLabel( dThemeGroup, "themeLabel" );
00074     themeLabel->setGeometry( QRect( 10, 50, 530, 40 ) );
00075     layout3->addWidget( dThemeGroup );
00076 
00077     dAppsGroup = new QGroupBox( privateLayoutWidget_3, "dAppsGroup" );
00078     dAppsGroup->setGeometry( QRect( 10, 200, 570, 50 ) );
00079     viewerLabel = new QLabel( dAppsGroup, "viewerLabel" );
00080     viewerLabel->setGeometry( QRect( 20, 24, 170, 22 ) );
00081     dViewer = new QLineEdit( dAppsGroup, "dViewer" );
00082     dViewer->setGeometry( QRect( 190, 20, 248, 22 ) );
00083     dViewer->setText( Viewer );
00084     browse_3 = new QPushButton( dAppsGroup, "browse_3" );
00085     browse_3->setGeometry( QRect( 440, 18, 100, 28 ) );
00086     layout3->addWidget( dAppsGroup );
00087 
00088     tabWidget->insertTab( Widget2, "" );
00089 
00090     Widget3 = new QWidget( tabWidget, "Widget3" );
00091 
00092     TagGroup = new QGroupBox( Widget3, "TagGroup" );
00093     TagGroup->setGeometry( QRect( 10, 10, 570, 60 ) );
00094 
00095     id3Check = new QCheckBox( TagGroup, "id3Check" );
00096     id3Check->setGeometry( QRect( 20, 18, 250, 21 ) );
00097     id3Check->setChecked(EnableID3);
00098 
00099     SaveId3Check = new QCheckBox( TagGroup, "SaveId3Check" );
00100     SaveId3Check->setGeometry( QRect( 260, 18, 250, 21 ) );
00101     SaveId3Check->setChecked(SaveID3);
00102 
00103     CoversGroup = new QGroupBox( Widget3, "CoversGroup" );
00104     CoversGroup->setGeometry( QRect( 10, 80, 570, 120 ) );
00105 
00106     CoverCheck = new QCheckBox( CoversGroup, "CoverCheck" );
00107     CoverCheck->setGeometry( QRect( 20, 18, 250, 21 ) );
00108     CoverCheck->setChecked(EnableCover);
00109 
00110     id3CoverCheck = new QCheckBox( CoversGroup, "id3CoverCheck" );
00111     id3CoverCheck->setGeometry( QRect( 260, 18, 250, 21 ) );
00112     id3CoverCheck->setChecked(EnableId3Cover);
00113 
00114     NetCoverCheck = new QCheckBox( CoversGroup, "NetCoverCheck" );
00115     NetCoverCheck->setGeometry( QRect( 260, 38, 300, 21 ) );
00116     NetCoverCheck->setChecked(NetCover);
00117 
00118     textLabel1 = new QLabel( CoversGroup, "textLabel1" );
00119     textLabel1->setGeometry( QRect( 20, 70, 250, 21 ) );
00120 
00121     cWidth = new QLineEdit( CoversGroup, "cWidth" );
00122     cWidth->setGeometry( QRect( 20, 90, 81, 21 ) );
00123     cWidth->setAlignment (Qt::AlignRight);
00124     cWidth->setText( QString::number( CoverWidth ) );
00125 
00126     textLabel2 = new QLabel( CoversGroup, "textLabel2" );
00127     textLabel2->setGeometry( QRect( 260, 70, 250, 21 ) );
00128 
00129     cHeight = new QLineEdit( CoversGroup, "cHeight" );
00130     cHeight->setGeometry( QRect( 260, 90, 81, 21 ) );
00131     cHeight->setAlignment (Qt::AlignRight);
00132     cHeight->setText( QString::number( CoverHeight ) );
00133 
00134     XmmsGroup = new QGroupBox( Widget3, "XmmsGroup" );
00135     XmmsGroup->setGeometry( QRect( 10, 210, 570, 60 ) );
00136 
00137     mainWinCheck = new QCheckBox( XmmsGroup, "mainWinCheck" );
00138     mainWinCheck->setGeometry( QRect( 20, 22, 250, 21 ) );
00139     mainWinCheck->setChecked(HideMainWin);
00140 
00141     tabWidget->insertTab( Widget3, "" );
00142 
00143     Widget4 = new QWidget( tabWidget, "Widget4" );
00144     QWidget* privateLayoutWidget_4 = new QWidget( Widget4, "layout4" );
00145     privateLayoutWidget_4->setGeometry( QRect( 10, 10, 570, 270 ) );
00146 
00147     Layout2 = new QGridLayout( privateLayoutWidget_4, 0, 0, KDialog::marginHint(), KDialog::spacingHint(), "Layout2");
00148 
00149     EmbedGroup = new QGroupBox( privateLayoutWidget_4, "EmbedGroup" );
00150     Layout6 = new QGridLayout( EmbedGroup, 0, 0, KDialog::marginHint(), KDialog::spacingHint(), "Layout6");
00151     Layout2->addWidget( EmbedGroup, 0, 0 );
00152     textLabel3 = new QLabel( EmbedGroup, "textLabel3" );
00153     textLabel3->setFixedSize( 250, 20 );
00154     Layout6->addWidget( textLabel3, 0, 0 );
00155     colorButton = new QPushButton( EmbedGroup, "colorButton" );
00156     colorButton->setText( bgc );
00157     colorButton->setPaletteBackgroundColor( bgColor );
00158     colorButton->setFixedSize( 100, 20 );
00159     Layout6->addWidget( colorButton, 0, 1 );
00160     Layout2->addWidget( EmbedGroup, 0, 0 );
00161 
00162     FadeGroup = new QGroupBox( privateLayoutWidget_4, "FadeGroup" );
00163     Layout4 = new QGridLayout( FadeGroup, 0, 0, KDialog::marginHint(), KDialog::spacingHint(), "Layout4");
00164     textLabel6 = new QLabel( FadeGroup, "textLabel6" );
00165     textLabel6->setFixedSize( 250, 20 );
00166     Layout4->addWidget( textLabel6, 0, 0 );
00167     fcolorButton = new QPushButton( FadeGroup, "fcolorButton" );
00168     fcolorButton->setText( fadec );
00169     fcolorButton->setPaletteBackgroundColor( fadeColor );
00170     fcolorButton->setFixedSize( 100, 20 );
00171     Layout4->addWidget( fcolorButton, 0, 1 );
00172     textLabel4 = new QLabel( FadeGroup, "textLabel4" );
00173     textLabel4->setFixedSize( 250, 20 );
00174     Layout4->addWidget( textLabel4, 1, 0 );
00175     fadeSpin = new QSpinBox(FadeGroup, "fadeSpin");
00176     fadeSpin->setMinValue(0);
00177     fadeSpin->setMaxValue(100);
00178     fadeSpin->setValue(int(fadeLevel*100));
00179     fadeSpin->setSuffix("%");
00180     fadeSpin->setFixedSize( 60, 20 );
00181     Layout4->addWidget( fadeSpin, 1, 1 );
00182     textLabel5 = new QLabel( FadeGroup, "textLabel5" );
00183     textLabel5->setFrameStyle( QFrame::GroupBoxPanel | QFrame::Sunken );
00184     textLabel5->setFixedSize( 64, 64 );
00185     Layout4->addMultiCellWidget( textLabel5, 0, 1, 2, 2 );
00186     slotTestFade(fadeSpin->value());
00187     Layout2->addWidget( FadeGroup, 1, 0 );
00188 
00189     tabWidget->insertTab( Widget4, "" );
00190 
00191     layout5->addWidget( tabWidget );
00192     languageChange();
00193     resize( QSize(600, 360).expandedTo(minimumSizeHint()) );
00194 
00195     toggleCover();
00196     // signals and slots connections
00197     connect( buttonOk, SIGNAL( clicked() ), this, SLOT( saveConfig() ) );
00198     connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00199     connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( help() ) );
00200     connect( browse_1, SIGNAL( clicked() ), this, SLOT( selThemeDir() ) );
00201     connect( browse_2, SIGNAL( clicked() ), this, SLOT( selDefaultTheme() ) );
00202     connect( browse_3, SIGNAL( clicked() ), this, SLOT( selDefaultViewer() ) );
00203     connect( colorButton, SIGNAL( clicked() ), this, SLOT( selColor() ) );
00204     connect( CoverCheck, SIGNAL( clicked() ), this, SLOT( toggleCover() ) );
00205     connect( id3Check, SIGNAL( clicked() ), this, SLOT( toggleCover() ) );
00206     connect( fadeSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotTestFade( int ) ) );
00207     connect( fcolorButton, SIGNAL( clicked() ), this, SLOT( selFadeColor() ) );
00208 }
00209 
00210 /*
00211  *  Destroys the object and frees any allocated resources
00212  */
00213 KarambaConf::~KarambaConf()
00214 {
00215     // no need to delete child widgets, Qt does it all for us
00216 }
00217 
00218 /*
00219  *  Sets the strings of the subwidgets using the current
00220  *  language.
00221  */
00222 void KarambaConf::languageChange()
00223 {
00224     setCaption( tr2i18n( "Karamba Configuration" ) );
00225     buttonHelp->setText( tr2i18n( "&Help" ) );
00226     buttonHelp->setAccel( QKeySequence( tr2i18n( "F1" ) ) );
00227     buttonOk->setText( tr2i18n( "&OK" ) );
00228     buttonOk->setAccel( QKeySequence( QString::null ) );
00229     buttonCancel->setText( tr2i18n( "&Cancel" ) );
00230     buttonCancel->setAccel( QKeySequence( QString::null ) );
00231     dFolderGroup->setTitle( tr2i18n( "Default themes folder" ) );
00232     browse_1->setText( tr2i18n( "Browse" ) );
00233     dThemeGroup->setTitle( tr2i18n( "Default theme" ) );
00234     browse_2->setText( tr2i18n( "Browse" ) );
00235     themeLabel->setText( tr2i18n( "Set your default theme.\nIt will be load at Karamba startup.\nYou can set it null if you want the open dialog." ) );
00236     themeLabel->adjustSize ();
00237     dAppsGroup->setTitle( tr2i18n( "Helper applications" ) );
00238     viewerLabel->setText( tr2i18n( "Default image viewer:" ) );
00239     viewerLabel->adjustSize ();
00240     browse_3->setText( tr2i18n( "Browse" ) );
00241     tabWidget->changeTab( Widget2, tr2i18n( "Karamba" ) );
00242     TagGroup->setTitle( tr2i18n( "OGG and MP3 Tags" ) );
00243     id3Check->setText( tr2i18n( "Enable Tags read" ) );
00244     SaveId3Check->setText( tr2i18n( "Enable Tags save" ) );
00245     CoversGroup->setTitle( tr2i18n( "Covers" ) );
00246     CoverCheck->setText( tr2i18n( "Enable cover display" ) );
00247     CoverCheck->adjustSize();
00248     id3CoverCheck->setText( tr2i18n( "Enable ID3 cover search" ) );
00249     id3CoverCheck->adjustSize();
00250     NetCoverCheck->setText( tr2i18n( "Enable Internet cover search" ) );
00251     NetCoverCheck->adjustSize();
00252     textLabel1->setText( tr2i18n( "Max cover width" ) );
00253     textLabel1->adjustSize();
00254     textLabel2->setText( tr2i18n( "Max cover height" ) );
00255     textLabel2->adjustSize();
00256     XmmsGroup->setTitle( tr2i18n( "XMMS" ) );
00257     mainWinCheck->setText( tr2i18n( "Always hide XMMS main window" ) );
00258     tabWidget->changeTab( Widget3, tr2i18n( "XMMS Sensor" ) );
00259     tabWidget->changeTab( Widget4, tr2i18n( "Colors options" ) );
00260     EmbedGroup->setTitle( tr2i18n( "Embed color" ) );
00261     textLabel3->setText( tr2i18n( "Default embended background color:" ) );
00262     textLabel3->adjustSize();
00263     FadeGroup->setTitle( tr2i18n( "Fading options" ) );
00264     textLabel4->setText( tr2i18n( "Fading Level:" ) );
00265     textLabel4->adjustSize();
00266     textLabel6->setText( tr2i18n( "Fading Color:" ) );
00267     textLabel6->adjustSize();
00268 }
00269 
00270 void KarambaConf::loadConfig(){
00271   KSimpleConfig conf("karambarc",true);
00272   conf.setGroup("karamba");
00273   Dir = conf.readEntry("ThemeDir", locateLocal("data", "karamba/themes/"));
00274   Theme =  conf.readEntry("DefaultTheme", "");
00275   Viewer =  conf.readEntry("ImgViewer", "");
00276   conf.setGroup("XMMS");
00277   EnableID3 = conf.readBoolEntry("EnableId3",false);
00278   SaveID3 = conf.readBoolEntry("SaveId3",false);
00279   EnableCover = conf.readBoolEntry("EnableCover",false);
00280   EnableId3Cover = conf.readBoolEntry("EnableId3Cover",false);
00281   NetCover = conf.readBoolEntry("EnableNetCover",false);
00282   CoverWidth = conf.readNumEntry("CoverWidth",64);
00283   CoverHeight = conf.readNumEntry("CoverHeight",64);
00284   HideMainWin = conf.readBoolEntry("HideMainWin",false);
00285   conf.setGroup("Embed");
00286   bgc = conf.readEntry("bgColor","0,0,0");
00287   bgColor = conf.readColorEntry("bgColor", 0);
00288   fadeColor = conf.readColorEntry("fadeColor", 0);
00289   fadec = conf.readEntry("fadeColor", "0,0,0");
00290   fadeLevel = conf.readDoubleNumEntry("fadeLevel",0.2);
00291 }
00292 
00293 void KarambaConf::saveConfig(){
00294   KSimpleConfig conf("karambarc",false);
00295   conf.setGroup("karamba");
00296   conf.writeEntry("ThemeDir", dFolder->text());
00297   conf.writeEntry("DefaultTheme", dTheme->text());
00298   conf.writeEntry("ImgViewer", dViewer->text());
00299   conf.setGroup("XMMS");
00300   if(id3Check->isChecked() == true){
00301     conf.writeEntry("EnableId3", "true");
00302     if(id3CoverCheck->isChecked() == true){
00303       conf.writeEntry("EnableId3Cover", "true");
00304     }
00305     else{
00306       conf.writeEntry("EnableId3Cover", "false");
00307     }
00308     if(SaveId3Check->isChecked() == true){
00309       conf.writeEntry("SaveId3", "true");
00310     }
00311     else{
00312       conf.writeEntry("SaveId3", "false");
00313     }
00314   }
00315   else{
00316     conf.writeEntry("EnableId3", "false");
00317     conf.writeEntry("EnableId3Cover", "false");
00318     conf.writeEntry("SaveId3", "false");
00319   }
00320   if(CoverCheck->isChecked() == true){
00321     conf.writeEntry("EnableCover", "true");
00322     if(NetCoverCheck->isChecked() == true){
00323       conf.writeEntry("EnableNetCover", "true");
00324     }
00325     else{
00326       conf.writeEntry("EnableNetCover", "false");
00327     }
00328   }
00329   else{
00330     conf.writeEntry("EnableCover", "false");
00331     conf.writeEntry("EnableNetCover", "false");
00332     conf.writeEntry("EnableId3Cover", "false");
00333   }
00334   conf.writeEntry("CoverWidth", cWidth->text());
00335   conf.writeEntry("CoverHeight", cHeight->text());
00336   if(mainWinCheck->isChecked() == true){
00337     conf.writeEntry("HideMainWin", "true");
00338   }
00339   else{
00340     conf.writeEntry("HideMainWin", "false");
00341   }
00342   conf.setGroup("Embed");
00343   conf.writeEntry("bgColor", bgColor);
00344   conf.writeEntry("fadeColor", fadeColor);
00345   conf.writeEntry("fadeLevel", double(fadeSpin->value())/100);
00346   conf.sync();
00347   accept();
00348 }
00349 
00350 void KarambaConf::selThemeDir(){
00351   KDirSelectDialog dirName;
00352   KURL ndir;
00353   ndir = dirName.selectDirectory(Dir, false, 0, "Select default folder");
00354   if( ndir.path() != ""){
00355     dFolder->setText( ndir.path() );
00356   }
00357 }
00358 
00359 void KarambaConf::selDefaultTheme(){
00360     QString fileName;
00361     fileName = KFileDialog::getOpenFileName(Dir, "*.theme", 0, "Open configurations");
00362     QUrl url(fileName); //make QUrl from QString
00363     fileName = (url.dirPath() == Dir)?url.fileName():fileName; //verify if the theme is in default dir
00364     if( fileName != ""){
00365       dTheme->setText( fileName );
00366       Theme = fileName;
00367     }
00368 }
00369 
00370 void KarambaConf::selDefaultViewer(){
00371     QString fileName;
00372     fileName = KFileDialog::getOpenFileName(Dir, "*", 0, "Choose image viewer");
00373     if( fileName != ""){
00374       dViewer->setText( fileName );
00375       Viewer = fileName;
00376     }
00377 }
00378 
00379 void KarambaConf::toggleCover(){
00380   bool c = CoverCheck->isChecked();
00381   bool i = id3Check->isChecked();
00382   cWidth->setEnabled ( c );
00383   cHeight->setEnabled ( c );
00384   id3CoverCheck->setEnabled ( c && i );
00385   NetCoverCheck->setEnabled ( c );
00386   SaveId3Check->setEnabled ( i );
00387 }
00388 
00389 void KarambaConf::selColor(){
00390   int result = KColorDialog::getColor( bgColor );
00391   if ( result == KColorDialog::Accepted ){
00392     colorButton->setPaletteBackgroundColor( bgColor );
00393     bgc = QString::number(bgColor.red()) + "," + QString::number(bgColor.green()) + "," + QString::number(bgColor.blue());
00394     colorButton->setText( bgc );
00395   }
00396 }
00397 
00398 void KarambaConf::help(){
00399   KRun::runCommand( "khelpcenter help:/karamba" );
00400 }
00401 
00402 void KarambaConf::slotTestFade( int f=0 ){
00403   KIconLoader* i = new KIconLoader;
00404   KPixmap ftest;
00405   KPixmap ico;
00406   double val;
00407   ftest.resize(64, 64);
00408   ftest.fill(paletteBackgroundColor());
00409   ico = i->loadIcon( "kmenu", KIcon::Group(2), 64 );
00410   bitBlt(&ftest,0,0,&ico,0,Qt::CopyROP);
00411   val = double(f)/100;
00412   ftest = KPixmapEffect::fade(ftest, val, fadeColor);
00413   textLabel5->setPixmap(ftest);
00414 }
00415 
00416 void KarambaConf::selFadeColor(){
00417   int result = KColorDialog::getColor( fadeColor );
00418   if ( result == KColorDialog::Accepted ){
00419     fcolorButton->setPaletteBackgroundColor( fadeColor );
00420     fadec = QString::number(fadeColor.red()) + "," + QString::number(fadeColor.green()) + "," + QString::number(fadeColor.blue());
00421     fcolorButton->setText( fadec );
00422     slotTestFade(fadeSpin->value()); 
00423   }
00424 }
00425 
00426 #include "karambaconf.moc"

Generated on Mon May 16 13:59:20 2005 for karamba by  doxygen 1.3.9.1