1 /**************************************************************************
5 Unix Remote Printing Operation
6 Copyright (c) Arto Hyvättinen 2010
8 This file is part of URPO.
10 URPO is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 URPO is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
21 **************************************************************************/
23 #include "settingsdialog.h"
26 #include <QPushButton>
27 #include <QHBoxLayout>
29 #include <QVBoxLayout>
30 #include <QFileDialog>
32 #include "urpoconnectionsettings.h"
34 SettingsDialog::SettingsDialog(QWidget *parent) :
41 setWindowTitle(tr("Urpo Settings"));
43 serverEdit = new QLineEdit;
44 connect(serverEdit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString)));
46 userEdit = new QLineEdit;
47 identityEdit = new QLineEdit;
49 browseButton = new QPushButton(tr("Browse"));
50 connect(browseButton, SIGNAL(clicked()),this,SLOT(browse()));
51 okButton = new QPushButton(tr("Done"));
52 connect(okButton, SIGNAL(clicked()), this, SLOT(okay()) );
53 okButton->setEnabled(false);
55 helpButton = new QPushButton( tr("Help"));
58 QVBoxLayout* mainLayout = new QVBoxLayout;
60 QHBoxLayout* helpLayout = new QHBoxLayout;
61 helpLayout->addWidget( new QLabel(tr("Remote printing utility "
63 "Please read help.")));
64 helpLayout->addWidget(helpButton);
65 QGroupBox* helpBox = new QGroupBox();
66 helpBox->setLayout(helpLayout);
67 helpBox->setFlat(false);
68 mainLayout->addWidget(helpBox);
71 QHBoxLayout* serverLayout = new QHBoxLayout;
72 serverLayout->addWidget( new QLabel(tr("Host name or ip address")));
73 serverLayout->addWidget( serverEdit );
74 mainLayout->addLayout(serverLayout);
76 QHBoxLayout* userLayout = new QHBoxLayout;
77 userLayout->addWidget( new QLabel(tr("Username")));
78 userLayout->addWidget( userEdit );
79 mainLayout->addLayout(userLayout);
81 QHBoxLayout* idLayout = new QHBoxLayout;
82 idLayout->addWidget( new QLabel( tr("Identity file")));
83 idLayout->addWidget(identityEdit);
84 idLayout->addWidget( browseButton);
85 mainLayout->addLayout(idLayout);
87 mainLayout->addStretch();
89 QHBoxLayout* okLayout = new QHBoxLayout;
90 okLayout->addStretch();
91 okLayout->addWidget(okButton);
92 mainLayout->addLayout(okLayout);
94 setLayout(mainLayout);
99 void SettingsDialog::setSettings(UrpoConnectionSettings *settings)
101 // Init dialog from UrpoConnectionSetting
102 settings_ = settings;
103 serverEdit->setText( settings_->getHost());
104 userEdit->setText(settings_->getUserid());
105 identityEdit->setText(settings_->getIdentity());
109 void SettingsDialog::setHelp(QTextBrowser *helpWidget)
111 // Set widget activated in help button
112 helpWidget_ = helpWidget;
113 connect( helpButton, SIGNAL(clicked()), this, SLOT(showHelp()));
116 void SettingsDialog::okay()
121 settings_->setHost( serverEdit->text());
122 settings_->setUserid( userEdit->text());
123 settings_->setIdentity( identityEdit->text());
127 done(QDialog::Accepted);
130 done(QDialog::Rejected);
133 void SettingsDialog::showHelp()
135 // Activate help window
138 helpWidget_->raise();
139 helpWidget_->activateWindow();
142 void SettingsDialog::serverChanged(const QString& text)
144 // If there is a server setting, dialog will be accepted
145 // (if you have same userid in server and ssh key defined...)
147 okButton->setDisabled( text.isEmpty() );
150 void SettingsDialog::browse()
152 QString path = QFileDialog::getOpenFileName(this, tr("Identity file"));
154 identityEdit->setText(path);