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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/*
**************************************************************************
description
--------------------
copyright : (C) 2003 by Andreas Zehender
email : zehender@kde.org
copyright : (C) 2003 by Luis Carvalho
email : lpassos@oninetspeed.pt
**************************************************************************
**************************************************************************
* *
* 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. *
* *
**************************************************************************/
#include "pmobjectlibrarysettings.h"
#include "pmlibrarymanager.h"
#include "pmlibraryhandle.h"
#include "pmlibraryhandleedit.h"
#include "pmdebug.h"
#include <qlayout.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <klocale.h>
#include <kfiledialog.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
PMObjectLibrarySettings::PMObjectLibrarySettings( QWidget* parent, const char* name )
: PMSettingsDialogPage( parent, name )
{
QVBoxLayout* vlayout = new QVBoxLayout( this, 0, KDialog::spacingHint( ) );
QGroupBox* gb = new QGroupBox( i18n( "Libraries" ), this );
vlayout->addWidget( gb );
QHBoxLayout* hlayout = new QHBoxLayout( gb, KDialog::marginHint( ) + 5, KDialog::spacingHint( ) );
m_pObjectLibraries = new QListBox( gb );
connect( m_pObjectLibraries, SIGNAL( selectionChanged( ) ), SLOT( slotObjectLibraryChanged( ) ) );
hlayout->addWidget( m_pObjectLibraries );
QVBoxLayout* gvl = new QVBoxLayout( hlayout );
m_pCreateObjectLibrary = new QPushButton( i18n( "Create..." ), gb );
connect( m_pCreateObjectLibrary, SIGNAL( clicked( ) ), SLOT( slotCreateObjectLibrary( ) ) );
gvl->addWidget( m_pCreateObjectLibrary );
m_pRemoveObjectLibrary = new QPushButton( i18n( "Remove" ), gb );
connect( m_pRemoveObjectLibrary, SIGNAL( clicked( ) ), SLOT( slotRemoveObjectLibrary( ) ) );
gvl->addWidget( m_pRemoveObjectLibrary );
m_pImportObjectLibrary = new QPushButton( i18n( "Import" ), gb );
connect( m_pImportObjectLibrary, SIGNAL( clicked( ) ), SLOT( slotImportObjectLibrary( ) ) );
gvl->addWidget( m_pImportObjectLibrary );
m_pModifyObjectLibrary = new QPushButton( i18n( "Properties" ), gb );
connect( m_pModifyObjectLibrary, SIGNAL( clicked( ) ), SLOT( slotModifyObjectLibrary( ) ) );
gvl->addWidget( m_pModifyObjectLibrary );
gvl->addStretch( 1 );
gb = new QGroupBox( i18n( "Library Details" ), this );
QGridLayout* grid = new QGridLayout( gb, 4, 2, KDialog::marginHint( ) + 5, KDialog::spacingHint( ) );
QLabel* lbl = new QLabel( i18n( "Path" ), gb );
grid->addWidget( lbl, 0, 0 );
lbl = new QLabel( i18n( "Author" ), gb );
grid->addWidget( lbl, 1, 0 );
lbl = new QLabel( i18n( "Description" ), gb );
grid->addWidget( lbl, 2, 0 );
m_pLibraryPath = new QLabel( "", gb );
m_pLibraryAuthor = new QLabel( "", gb );
m_pLibraryDescription = new QLabel( "", gb );
m_pReadOnlyText = new QLabel( "", gb );
grid->addWidget( m_pLibraryPath, 0, 1 );
grid->addWidget( m_pLibraryAuthor, 1, 1 );
grid->addWidget( m_pLibraryDescription, 2, 1 );
grid->addMultiCellWidget( m_pReadOnlyText, 3, 3, 0, 1 );
grid->setColStretch( 1, 1 );
vlayout->addWidget( gb );
vlayout->addStretch( 1 );
}
void PMObjectLibrarySettings::displaySettings( )
{
m_pObjectLibraries->clear( );
m_pObjectLibraries->insertStringList( PMLibraryManager::theManager( )->availableLibraries( ) );
}
void PMObjectLibrarySettings::applySettings( )
{
}
bool PMObjectLibrarySettings::validateData( )
{
return true;
}
void PMObjectLibrarySettings::displayDefaults( )
{
}
void PMObjectLibrarySettings::slotImportObjectLibrary( )
{
// TODO
}
void PMObjectLibrarySettings::slotModifyObjectLibrary( )
{
PMLibraryHandle* h = PMLibraryManager::theManager( )->getLibraryHandle( m_pObjectLibraries->currentText( ) );
if( h )
{
PMLibraryHandleEdit h_dlg( h, this );
if( h_dlg.exec( ) == QDialog::Accepted )
{
h->saveLibraryInfo( );
displaySettings( );
for( unsigned i = 0; i < m_pObjectLibraries->count( ); ++i )
{
if( m_pObjectLibraries->text( i ) == h->name( ) )
{
m_pObjectLibraries->setSelected( i, true );
break;
}
}
slotObjectLibraryChanged( );
}
}
}
void PMObjectLibrarySettings::slotRemoveObjectLibrary( )
{
m_pObjectLibraries->removeItem( m_pObjectLibraries->currentItem( ) );
}
void PMObjectLibrarySettings::slotCreateObjectLibrary( )
{
PMLibraryHandle h;
PMLibraryHandleEdit h_dlg( &h, this );
QString libfilename;
if( h_dlg.exec( ) == QDialog::Accepted )
{
libfilename = h.name( );
h.setPath( locateLocal( "appdata", "library/" ) + libfilename.stripWhiteSpace( ) + "/" );
// Create the new library
switch( h.createLibrary( ) )
{
case PMLibraryHandle::Ok:
PMLibraryManager::theManager( )->refresh( );
displaySettings( );
break;
case PMLibraryHandle::ExistingDir:
KMessageBox::error( this, i18n( "The folder already exists." ) );
break;
case PMLibraryHandle::CouldNotCreateDir:
KMessageBox::error( this, i18n( "Could not create the folder." ) );
break;
default:
kdError( PMArea ) << "Unexpected error in slotCreateObjectLibrary." << endl;
}
}
}
void PMObjectLibrarySettings::slotObjectLibraryChanged( )
{
PMLibraryHandle* h = PMLibraryManager::theManager( )->getLibraryHandle( m_pObjectLibraries->currentText( ) );
if( h )
{
m_pLibraryPath->setText( h->path( ) );
m_pLibraryAuthor->setText( h->author( ) );
m_pLibraryDescription->setText( h->description( ) );
if( h->isReadOnly( ) )
m_pReadOnlyText->setText( i18n( "This library is not modifiable." ) );
else
m_pReadOnlyText->setText( i18n( "This library is modifiable." ) );
}
else
{
m_pLibraryPath->setText( "" );
m_pLibraryAuthor->setText( "" );
m_pLibraryDescription->setText( "" );
m_pReadOnlyText->setText( "" );
}
}
#include "pmobjectlibrarysettings.moc"
|