| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2008 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "config.h" |
|---|
| 22 | |
|---|
| 23 | #include "filenameedit.h" |
|---|
| 24 | |
|---|
| 25 | #ifndef USE_KDE |
|---|
| 26 | #include <QFileDialog> |
|---|
| 27 | #include <QLineEdit> |
|---|
| 28 | #include <QHBoxLayout> |
|---|
| 29 | #include <QToolButton> |
|---|
| 30 | #endif |
|---|
| 31 | |
|---|
| 32 | using namespace LicqQtGui; |
|---|
| 33 | /* TRANSLATOR LicqQtGui::FileNameEdit */ |
|---|
| 34 | |
|---|
| 35 | FileNameEdit::FileNameEdit(QWidget* parent) |
|---|
| 36 | : FILENAMEEDIT_BASE(parent) |
|---|
| 37 | { |
|---|
| 38 | #ifndef USE_KDE |
|---|
| 39 | QHBoxLayout* lay = new QHBoxLayout(this); |
|---|
| 40 | lay->setContentsMargins(0, 0, 0, 0); |
|---|
| 41 | |
|---|
| 42 | // Input field |
|---|
| 43 | editField = new QLineEdit(); |
|---|
| 44 | lay->addWidget(editField); |
|---|
| 45 | |
|---|
| 46 | // Button to open file dialog |
|---|
| 47 | QToolButton* browseButton = new QToolButton(); |
|---|
| 48 | // TODO: Use an open file icon instead of text for browseButton |
|---|
| 49 | browseButton->setText(tr("Browse...")); |
|---|
| 50 | connect(browseButton, SIGNAL(clicked()), SLOT(browse())); |
|---|
| 51 | lay->addWidget(browseButton); |
|---|
| 52 | #endif |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | void FileNameEdit::setFileName(const QString& fileName) |
|---|
| 56 | { |
|---|
| 57 | #ifdef USE_KDE |
|---|
| 58 | setUrl(KUrl(fileName)); |
|---|
| 59 | #else |
|---|
| 60 | editField->setText(fileName); |
|---|
| 61 | #endif |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | QString FileNameEdit::fileName() const |
|---|
| 65 | { |
|---|
| 66 | #ifdef USE_KDE |
|---|
| 67 | return url().pathOrUrl(); |
|---|
| 68 | #else |
|---|
| 69 | return editField->text(); |
|---|
| 70 | #endif |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | #ifndef USE_KDE |
|---|
| 74 | void FileNameEdit::browse() |
|---|
| 75 | { |
|---|
| 76 | QString filename = QFileDialog::getOpenFileName(this, QString(), editField->text(), QString()); |
|---|
| 77 | |
|---|
| 78 | if (filename.isNull()) |
|---|
| 79 | return; |
|---|
| 80 | |
|---|
| 81 | editField->setText(filename); |
|---|
| 82 | } |
|---|
| 83 | #endif |
|---|