2011-12-27 15:49:06 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* 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 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "EditGroupWidget.h"
|
2012-05-14 19:10:54 +02:00
|
|
|
#include "ui_EditGroupWidgetMain.h"
|
2011-12-27 15:49:06 +01:00
|
|
|
|
2012-05-15 16:50:42 +02:00
|
|
|
#include "core/Metadata.h"
|
2012-05-15 13:31:56 +02:00
|
|
|
#include "gui/EditWidgetIcons.h"
|
2012-10-29 22:41:37 +01:00
|
|
|
#include "gui/EditWidgetProperties.h"
|
2012-05-15 13:31:56 +02:00
|
|
|
|
2011-12-27 15:49:06 +01:00
|
|
|
EditGroupWidget::EditGroupWidget(QWidget* parent)
|
2012-05-14 19:10:54 +02:00
|
|
|
: EditWidget(parent)
|
|
|
|
, m_mainUi(new Ui::EditGroupWidgetMain())
|
|
|
|
, m_editGroupWidgetMain(new QWidget())
|
2012-05-15 13:31:56 +02:00
|
|
|
, m_editGroupWidgetIcons(new EditWidgetIcons())
|
2012-10-29 22:41:37 +01:00
|
|
|
, m_editWidgetProperties(new EditWidgetProperties())
|
2012-06-29 14:15:16 +02:00
|
|
|
, m_group(Q_NULLPTR)
|
2013-04-14 15:07:47 +02:00
|
|
|
, m_database(Q_NULLPTR)
|
2011-12-27 15:49:06 +01:00
|
|
|
{
|
2012-05-14 19:10:54 +02:00
|
|
|
m_mainUi->setupUi(m_editGroupWidgetMain);
|
2011-12-27 15:49:06 +01:00
|
|
|
|
2012-05-14 19:10:54 +02:00
|
|
|
add(tr("Group"), m_editGroupWidgetMain);
|
2012-05-15 13:31:56 +02:00
|
|
|
add(tr("Icon"), m_editGroupWidgetIcons);
|
2012-10-29 19:26:24 +01:00
|
|
|
add(tr("Properties"), m_editWidgetProperties);
|
2012-05-14 19:10:54 +02:00
|
|
|
|
2012-10-20 17:53:33 +02:00
|
|
|
addTriStateItems(m_mainUi->searchComboBox);
|
|
|
|
addTriStateItems(m_mainUi->autotypeComboBox);
|
2012-05-18 16:19:28 +02:00
|
|
|
|
2012-05-18 10:52:05 +02:00
|
|
|
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
|
|
|
|
|
2012-05-14 19:10:54 +02:00
|
|
|
connect(this, SIGNAL(accepted()), SLOT(save()));
|
|
|
|
connect(this, SIGNAL(rejected()), SLOT(cancel()));
|
2011-12-27 15:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EditGroupWidget::~EditGroupWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-15 13:31:56 +02:00
|
|
|
void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)
|
2011-12-27 15:49:06 +01:00
|
|
|
{
|
|
|
|
m_group = group;
|
2012-05-15 16:50:42 +02:00
|
|
|
m_database = database;
|
2011-12-27 15:49:06 +01:00
|
|
|
|
|
|
|
if (create) {
|
2012-05-27 11:12:12 +02:00
|
|
|
setHeadline(tr("Add group"));
|
2011-12-27 15:49:06 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-05-27 11:12:12 +02:00
|
|
|
setHeadline(tr("Edit group"));
|
2011-12-27 15:49:06 +01:00
|
|
|
}
|
|
|
|
|
2012-05-14 19:10:54 +02:00
|
|
|
m_mainUi->editName->setText(m_group->name());
|
|
|
|
m_mainUi->editNotes->setPlainText(m_group->notes());
|
2012-05-18 10:52:05 +02:00
|
|
|
m_mainUi->expireCheck->setChecked(group->timeInfo().expires());
|
|
|
|
m_mainUi->expireDatePicker->setDateTime(group->timeInfo().expiryTime().toLocalTime());
|
2012-10-20 17:53:33 +02:00
|
|
|
m_mainUi->searchComboBox->setCurrentIndex(indexFromTriState(group->searchingEnabled()));
|
|
|
|
m_mainUi->autotypeComboBox->setCurrentIndex(indexFromTriState(group->autoTypeEnabled()));
|
2012-05-14 19:10:54 +02:00
|
|
|
|
2012-05-15 13:31:56 +02:00
|
|
|
IconStruct iconStruct;
|
|
|
|
iconStruct.uuid = group->iconUuid();
|
|
|
|
iconStruct.number = group->iconNumber();
|
|
|
|
m_editGroupWidgetIcons->load(group->uuid(), database, iconStruct);
|
2012-04-23 23:19:29 +02:00
|
|
|
|
2012-10-29 22:41:37 +01:00
|
|
|
m_editWidgetProperties->setFields(group->timeInfo(), group->uuid());
|
|
|
|
|
2012-05-18 10:52:05 +02:00
|
|
|
setCurrentRow(0);
|
|
|
|
|
2012-05-14 19:10:54 +02:00
|
|
|
m_mainUi->editName->setFocus();
|
2011-12-27 15:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditGroupWidget::save()
|
|
|
|
{
|
2012-05-14 19:10:54 +02:00
|
|
|
m_group->setName(m_mainUi->editName->text());
|
|
|
|
m_group->setNotes(m_mainUi->editNotes->toPlainText());
|
2012-05-18 10:52:05 +02:00
|
|
|
m_group->setExpires(m_mainUi->expireCheck->isChecked());
|
|
|
|
m_group->setExpiryTime(m_mainUi->expireDatePicker->dateTime().toUTC());
|
2012-10-20 17:53:33 +02:00
|
|
|
|
|
|
|
m_group->setSearchingEnabled(triStateFromIndex(m_mainUi->searchComboBox->currentIndex()));
|
|
|
|
m_group->setAutoTypeEnabled(triStateFromIndex(m_mainUi->autotypeComboBox->currentIndex()));
|
2011-12-27 15:49:06 +01:00
|
|
|
|
2012-05-15 13:31:56 +02:00
|
|
|
IconStruct iconStruct = m_editGroupWidgetIcons->save();
|
|
|
|
|
2012-05-15 16:50:42 +02:00
|
|
|
if (iconStruct.number < 0) {
|
|
|
|
m_group->setIcon(Group::DefaultIconNumber);
|
|
|
|
}
|
|
|
|
else if (iconStruct.uuid.isNull()) {
|
2012-05-15 13:31:56 +02:00
|
|
|
m_group->setIcon(iconStruct.number);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_group->setIcon(iconStruct.uuid);
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:15:16 +02:00
|
|
|
m_group = Q_NULLPTR;
|
|
|
|
m_database = Q_NULLPTR;
|
2011-12-27 15:49:06 +01:00
|
|
|
Q_EMIT editFinished(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditGroupWidget::cancel()
|
|
|
|
{
|
2012-05-15 16:50:42 +02:00
|
|
|
if (!m_group->iconUuid().isNull() &&
|
|
|
|
!m_database->metadata()->containsCustomIcon(m_group->iconUuid())) {
|
|
|
|
m_group->setIcon(Entry::DefaultIconNumber);
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:15:16 +02:00
|
|
|
m_group = Q_NULLPTR;
|
|
|
|
m_database = Q_NULLPTR;
|
2011-12-27 15:49:06 +01:00
|
|
|
Q_EMIT editFinished(false);
|
|
|
|
}
|
2012-10-20 17:53:33 +02:00
|
|
|
|
|
|
|
void EditGroupWidget::addTriStateItems(QComboBox* comboBox)
|
|
|
|
{
|
2012-10-21 15:11:09 +02:00
|
|
|
comboBox->addItem(tr("Inherit"));
|
|
|
|
comboBox->addItem(tr("Enable"));
|
|
|
|
comboBox->addItem(tr("Disable"));
|
2012-10-20 17:53:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int EditGroupWidget::indexFromTriState(Group::TriState triState)
|
|
|
|
{
|
|
|
|
switch (triState) {
|
|
|
|
case Group::Inherit:
|
|
|
|
return 0;
|
|
|
|
case Group::Enable:
|
|
|
|
return 1;
|
|
|
|
case Group::Disable:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Group::TriState EditGroupWidget::triStateFromIndex(int index)
|
|
|
|
{
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
return Group::Inherit;
|
|
|
|
case 1:
|
|
|
|
return Group::Enable;
|
|
|
|
case 2:
|
|
|
|
return Group::Disable;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
return Group::Inherit;
|
|
|
|
}
|
|
|
|
}
|