┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tagcloud/newtagdialog.cpp
blob: 8785d578c1c72126f413c7258f6e48c5a795d89a (plain)
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
85
86
87
88
89
90
91
92
93
94
95
/*
   Copyright (C) 2008 by Sebastian Trueg <trueg at kde.org>

   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)
   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, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "newtagdialog.h"

#include <nepomuk/tag.h>

#include <KDebug>
#include <KLocale>
#include <KTitleWidget>


NewTagDialog::NewTagDialog( QWidget* parent )
    : KDialog( parent )
{
    setCaption( i18nc( "@title:window", "Create New Tag" ) );
    setButtons( Ok|Cancel );
    enableButtonOk( false );

    setupUi( mainWidget() );

    connect( m_editTagLabel, SIGNAL( textChanged(const QString&) ),
             this, SLOT( slotLabelChanged(const QString&) ) );

    // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?)
    KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog");
    restoreDialogSize(group);
}


NewTagDialog::~NewTagDialog()
{
    // TODO: use KGlobal::config() if NewTagDialog will be moved to kdelibs (KDE 4.2?)
    KConfigGroup group(KSharedConfig::openConfig("dolphinrc"), "NewTagDialog");
    saveDialogSize(group, KConfigBase::Persistent);
}


QSize NewTagDialog::sizeHint() const
{
    return QSize(400, 256);
}

void NewTagDialog::slotLabelChanged( const QString& text )
{
    enableButtonOk( !text.isEmpty() );
}


Nepomuk::Tag NewTagDialog::createTag( QWidget* parent )
{
    NewTagDialog dlg( parent );
    dlg.m_labelTitle->setText( i18nc( "@title:window", "Create New Tag" ) );
    dlg.m_labelTitle->setComment( i18nc( "@title:window subtitle to previous message", "with optional icon and description" ) );
    dlg.m_labelTitle->setPixmap( KIcon( "nepomuk" ).pixmap( 32, 32 ) );

    dlg.m_editTagLabel->setFocus();

    if ( dlg.exec() ) {
        QString name = dlg.m_editTagLabel->text();
        QString comment = dlg.m_editTagComment->text();
        QString icon = dlg.m_buttonTagIcon->icon();

        Nepomuk::Tag newTag( name );
        newTag.setLabel( name );
        newTag.addIdentifier( name );
        if ( !comment.isEmpty() ) {
            newTag.setDescription( comment );
        }
        if ( !icon.isEmpty() ) {
            newTag.addSymbol( icon );
        }
        return newTag;
    }
    else {
        return Nepomuk::Tag();
    }
}

#include "newtagdialog.moc"