]> cloud.milkyroute.net Git - dolphin.git/blob - src/tagcloud/newtagdialog.cpp
8785d578c1c72126f413c7258f6e48c5a795d89a
[dolphin.git] / src / tagcloud / newtagdialog.cpp
1 /*
2 Copyright (C) 2008 by Sebastian Trueg <trueg at kde.org>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "newtagdialog.h"
20
21 #include <nepomuk/tag.h>
22
23 #include <KDebug>
24 #include <KLocale>
25 #include <KTitleWidget>
26
27
28 NewTagDialog::NewTagDialog( QWidget* parent )
29 : KDialog( parent )
30 {
31 setCaption( i18nc( "@title:window", "Create New Tag" ) );
32 setButtons( Ok|Cancel );
33 enableButtonOk( false );
34
35 setupUi( mainWidget() );
36
37 connect( m_editTagLabel, SIGNAL( textChanged(const QString&) ),
38 this, SLOT( slotLabelChanged(const QString&) ) );
39
40 // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?)
41 KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog");
42 restoreDialogSize(group);
43 }
44
45
46 NewTagDialog::~NewTagDialog()
47 {
48 // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?)
49 KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog");
50 saveDialogSize(group, KConfigBase::Persistent);
51 }
52
53
54 QSize NewTagDialog::sizeHint() const
55 {
56 return QSize(400, 256);
57 }
58
59 void NewTagDialog::slotLabelChanged( const QString& text )
60 {
61 enableButtonOk( !text.isEmpty() );
62 }
63
64
65 Nepomuk::Tag NewTagDialog::createTag( QWidget* parent )
66 {
67 NewTagDialog dlg( parent );
68 dlg.m_labelTitle->setText( i18nc( "@title:window", "Create New Tag" ) );
69 dlg.m_labelTitle->setComment( i18nc( "@title:window subtitle to previous message", "with optional icon and description" ) );
70 dlg.m_labelTitle->setPixmap( KIcon( "nepomuk" ).pixmap( 32, 32 ) );
71
72 dlg.m_editTagLabel->setFocus();
73
74 if ( dlg.exec() ) {
75 QString name = dlg.m_editTagLabel->text();
76 QString comment = dlg.m_editTagComment->text();
77 QString icon = dlg.m_buttonTagIcon->icon();
78
79 Nepomuk::Tag newTag( name );
80 newTag.setLabel( name );
81 newTag.addIdentifier( name );
82 if ( !comment.isEmpty() ) {
83 newTag.setDescription( comment );
84 }
85 if ( !icon.isEmpty() ) {
86 newTag.addSymbol( icon );
87 }
88 return newTag;
89 }
90 else {
91 return Nepomuk::Tag();
92 }
93 }
94
95 #include "newtagdialog.moc"