1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*
* edititemdlg.cpp - plugin
* Copyright (C) 2010 Evgeny Khryukin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "edititemdlg.h"
#include "iconfactoryaccessinghost.h"
#include "optionaccessinghost.h"
#include <QFileDialog>
static const QString splitStr = "&split&";
EditItemDlg::EditItemDlg(IconFactoryAccessingHost *icoHost, OptionAccessingHost *psiOptions_, QWidget *p) :
QDialog(p, Qt::Window), psiOptions(psiOptions_)
{
setAttribute(Qt::WA_DeleteOnClose);
// setModal(true);
ui_.setupUi(this);
ui_.tb_open->setIcon(icoHost->getIcon("psi/browse"));
ui_.tb_test->setIcon(icoHost->getIcon("psi/play"));
connect(ui_.tb_test, &QToolButton::pressed, this, &EditItemDlg::doTestSound);
connect(ui_.tb_open, &QToolButton::pressed, this, &EditItemDlg::getFileName);
}
void EditItemDlg::init(const QString &settings)
{
QStringList l = settings.split(splitStr);
if (!l.isEmpty()) {
ui_.le_jid->setText(l.takeFirst());
ui_.le_jid->setEnabled(!ui_.le_jid->text().isEmpty());
ui_.rb_text->setChecked(ui_.le_jid->text().isEmpty());
}
if (!l.isEmpty()) {
ui_.te_text->setText(l.takeFirst());
ui_.te_text->setEnabled(!ui_.te_text->toPlainText().isEmpty());
ui_.rb_jid->setChecked(ui_.te_text->toPlainText().isEmpty());
}
if (!l.isEmpty())
ui_.le_sound->setText(l.takeFirst());
if (!l.isEmpty())
ui_.cb_always_play->setChecked(l.takeFirst().toInt());
if (!l.isEmpty())
ui_.rb_groupchat->setChecked(l.takeFirst().toInt());
}
void EditItemDlg::getFileName()
{
QString fileName = QFileDialog::getOpenFileName(nullptr, tr("Choose a sound file"),
psiOptions->getPluginOption(constLastFile, QVariant("")).toString(),
tr("Sound (*.wav)"));
if (fileName.isEmpty())
return;
QFileInfo fi(fileName);
psiOptions->setPluginOption(constLastFile, QVariant(fi.absolutePath()));
ui_.le_sound->setText(fileName);
}
void EditItemDlg::doTestSound() { emit testSound(ui_.le_sound->text()); }
void EditItemDlg::accept()
{
QString str = (ui_.rb_jid->isChecked() ? ui_.le_jid->text() : "") + splitStr;
str += (ui_.rb_text->isChecked() ? ui_.te_text->toPlainText() : "") + splitStr;
str += ui_.le_sound->text() + splitStr;
str += (ui_.cb_always_play->isChecked() ? "1" : "0") + splitStr;
str += ui_.rb_groupchat->isChecked() ? "1" : "0";
emit dlgAccepted(str);
close();
}
|