00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "settingsdialog.h"
00024
00025 #include <QLineEdit>
00026 #include <QPushButton>
00027 #include <QHBoxLayout>
00028 #include <QLabel>
00029 #include <QVBoxLayout>
00030 #include <QFileDialog>
00031 #include <QGroupBox>
00032 #include "urpoconnectionsettings.h"
00033
00034 SettingsDialog::SettingsDialog(QWidget *parent) :
00035 QDialog(parent)
00036 {
00037 settings_ = 0;
00038 helpWidget_ = 0;
00039
00040
00041 setWindowTitle(tr("Urpo Settings"));
00042
00043 serverEdit = new QLineEdit;
00044 connect(serverEdit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString)));
00045
00046 userEdit = new QLineEdit;
00047 identityEdit = new QLineEdit;
00048
00049 browseButton = new QPushButton(tr("Browse"));
00050 connect(browseButton, SIGNAL(clicked()),this,SLOT(browse()));
00051 okButton = new QPushButton(tr("Done"));
00052 connect(okButton, SIGNAL(clicked()), this, SLOT(okay()) );
00053 okButton->setEnabled(false);
00054
00055 helpButton = new QPushButton( tr("Help"));
00056
00057
00058 QVBoxLayout* mainLayout = new QVBoxLayout;
00059
00060 QHBoxLayout* helpLayout = new QHBoxLayout;
00061 helpLayout->addWidget( new QLabel(tr("Remote printing utility "
00062 "via ssh and cups. "
00063 "Please read help.")));
00064 helpLayout->addWidget(helpButton);
00065 QGroupBox* helpBox = new QGroupBox();
00066 helpBox->setLayout(helpLayout);
00067 helpBox->setFlat(false);
00068 mainLayout->addWidget(helpBox);
00069
00070
00071 QHBoxLayout* serverLayout = new QHBoxLayout;
00072 serverLayout->addWidget( new QLabel(tr("Host name or ip address")));
00073 serverLayout->addWidget( serverEdit );
00074 mainLayout->addLayout(serverLayout);
00075
00076 QHBoxLayout* userLayout = new QHBoxLayout;
00077 userLayout->addWidget( new QLabel(tr("Username")));
00078 userLayout->addWidget( userEdit );
00079 mainLayout->addLayout(userLayout);
00080
00081 QHBoxLayout* idLayout = new QHBoxLayout;
00082 idLayout->addWidget( new QLabel( tr("Identity file")));
00083 idLayout->addWidget(identityEdit);
00084 idLayout->addWidget( browseButton);
00085 mainLayout->addLayout(idLayout);
00086
00087 mainLayout->addStretch();
00088
00089 QHBoxLayout* okLayout = new QHBoxLayout;
00090 okLayout->addStretch();
00091 okLayout->addWidget(okButton);
00092 mainLayout->addLayout(okLayout);
00093
00094 setLayout(mainLayout);
00095
00096 }
00097
00098
00099 void SettingsDialog::setSettings(UrpoConnectionSettings *settings)
00100 {
00101
00102 settings_ = settings;
00103 serverEdit->setText( settings_->getHost());
00104 userEdit->setText(settings_->getUserid());
00105 identityEdit->setText(settings_->getIdentity());
00106
00107 }
00108
00109 void SettingsDialog::setHelp(QTextBrowser *helpWidget)
00110 {
00111
00112 helpWidget_ = helpWidget;
00113 connect( helpButton, SIGNAL(clicked()), this, SLOT(showHelp()));
00114 }
00115
00116 void SettingsDialog::okay()
00117 {
00118 if( settings_ )
00119 {
00120
00121 settings_->setHost( serverEdit->text());
00122 settings_->setUserid( userEdit->text());
00123 settings_->setIdentity( identityEdit->text());
00124
00125 settings_->store();
00126
00127 done(QDialog::Accepted);
00128 }
00129 else
00130 done(QDialog::Rejected);
00131 }
00132
00133 void SettingsDialog::showHelp()
00134 {
00135
00136 helpWidget_->home();
00137 helpWidget_->show();
00138 helpWidget_->raise();
00139 helpWidget_->activateWindow();
00140 }
00141
00142 void SettingsDialog::serverChanged(const QString& text)
00143 {
00144
00145
00146
00147 okButton->setDisabled( text.isEmpty() );
00148 }
00149
00150 void SettingsDialog::browse()
00151 {
00152 QString path = QFileDialog::getOpenFileName(this, tr("Identity file"));
00153 if(!path.isNull())
00154 identityEdit->setText(path);
00155 }