4 * @author Toni Jussila <toni.jussila@fudeco.com>
5 * @copyright (c) 2010 Speed Freak team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 #include <QFileDialog>
12 #include <QMessageBox>
16 #include "profiledialog.h"
17 #include "ui_profiledialog.h"
18 #include "usersettings.h"
19 #include "settingsdialog.h"
20 #include "xmlreader.h"
23 * Constructor of this class.
25 * @param QWidget pointer to parent object. By default the value is NULL.
27 ProfileDialog::ProfileDialog(SettingsDialog *parent) : QDialog(parent), ui(new Ui::ProfileDialog)
29 qDebug() << "__ProfileDialog";
34 this->setWindowTitle("Profile - " + parent->getUserName());
38 this->setWindowTitle("Profile");
42 ui->labelInfoToUser->setVisible(0);
43 ui->labelInfoToUser->setText("");
46 imageButtonState = false;
54 // Read user profile xml
55 QString filename = "/home/user/MyDocs/speedfreak/profile/" + parent->getUserName() + "_profile.xml";
58 if (!file.open(QFile::ReadOnly))
60 qDebug() << "_xmlRead fail";
65 xmlReader = new XmlReader();
66 xmlReader->xmlReadProfile(&file,this);
72 * Destructor of this class. Deletes all dynamic objects and sets them to NULL.
74 ProfileDialog::~ProfileDialog()
76 qDebug() << "__~ProfileDialog";
88 void ProfileDialog::changeEvent(QEvent *e)
90 QDialog::changeEvent(e);
92 case QEvent::LanguageChange:
93 ui->retranslateUi(this);
101 * This slot function called when image button clicked.
104 void ProfileDialog::on_buttonImage_clicked()
106 if (imageButtonState == false)
108 ui->buttonImage->setText("Load image");
112 ui->buttonImage->setText("Change image");
115 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());
116 loadPicture(fileName);
120 * This function load picture.
122 * @param QString file name
124 void ProfileDialog::loadPicture(QString fileName)
126 if (!fileName.isEmpty())
128 QImage image(fileName);
131 QMessageBox::information(this, tr("Profile"),tr("Cannot load %1.").arg(fileName));
134 ui->labelImage->setPixmap(QPixmap::fromImage(image.scaled(QSize(120,120), Qt::KeepAspectRatio)));
140 * This slot function called when save button clicked.
142 * @todo server connection
144 void ProfileDialog::on_buttonSave_clicked()
147 setManufacturer(ui->lineEditManufacturer->text());
148 setType(ui->lineEditType->text());
149 setModel(ui->lineEditModel->text());
150 setDescription(ui->textEditDescription->toPlainText());
153 // emit settingsdialog --> mainwindow --> httpclient
154 //emit saveprofile();
158 * Get function return manufacturer.
160 * @return QString manufacturer
162 QString ProfileDialog::getManufacturer()
168 * Get function return type.
170 * @return QString type
172 QString ProfileDialog::getType()
178 * Get function return model.
180 * @return QString model
182 QString ProfileDialog::getModel()
188 * Get function return description.
190 * @return QString description
192 QString ProfileDialog::getDescription()
198 * Get function return picture.
200 * @return QString picture
202 QString ProfileDialog::getPicture()
208 * This function set manufacturer.
210 * @param QString manufacturer
212 void ProfileDialog::setManufacturer(QString m)
215 ui->lineEditManufacturer->setText(m);
219 * This function set type.
221 * @param QString type
223 void ProfileDialog::setType(QString t)
226 ui->lineEditType->setText(t);
230 * This function set model.
232 * @param QString model
234 void ProfileDialog::setModel(QString m)
237 ui->lineEditModel->setText(m);
241 * This function set description.
243 * @param QString description
245 void ProfileDialog::setDescription(QString d)
248 ui->textEditDescription->setText(d);
252 * This function set description.
254 * @param QString picture
256 void ProfileDialog::setPicture(QString p)
263 * This function set label info text to user.
265 * @param QString info text
267 void ProfileDialog::setLabelInfoToUser(QString infoText)
269 ui->labelInfoToUser->setVisible(1);
270 this->ui->labelInfoToUser->setText(infoText);