1/* This file is part of the KDE project
2 Copyright (C) 20079 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kptinsertfiledlg.h"
21#include "kptnode.h"
22#include "kptproject.h"
23
24#include <klocale.h>
25#include <kio/netaccess.h>
26#include <kdebug.h>
27
28#include <QRadioButton>
29
30namespace KPlato
31{
32
33InsertFileDialog::InsertFileDialog( Project &project, Node *currentNode, QWidget *parent )
34 : KDialog(parent)
35{
36 setCaption( i18n("Insert File") );
37 setButtons( KDialog::Ok | KDialog::Cancel );
38 setDefaultButton( Ok );
39 showButtonSeparator( true );
40
41 m_panel = new InsertFilePanel( project, currentNode, this );
42
43 setMainWidget( m_panel );
44
45 enableButtonOk(false);
46
47 connect( m_panel, SIGNAL(enableButtonOk(bool)), SLOT(enableButtonOk(bool)) );
48}
49
50KUrl InsertFileDialog::url() const
51{
52 return m_panel->url();
53}
54
55Node *InsertFileDialog::parentNode() const
56{
57 return m_panel->parentNode();
58}
59
60Node *InsertFileDialog::afterNode() const
61{
62 return m_panel->afterNode();
63}
64
65//------------------------
66InsertFilePanel::InsertFilePanel( Project &project, Node *currentNode, QWidget *parent )
67 : QWidget( parent ),
68 m_project( project ),
69 m_node( currentNode )
70{
71 ui.setupUi( this );
72
73 if ( currentNode == 0 || currentNode->type() == Node::Type_Project ) {
74 ui.ui_isAfter->setEnabled( false );
75 ui.ui_isParent->setEnabled( false );
76 ui.ui_useProject->setChecked( true );
77
78 ui.ui_name->setText( project.name() );
79 } else {
80 ui.ui_isAfter->setChecked( true );
81
82 ui.ui_name->setText( currentNode->name() );
83 }
84 connect( ui.ui_url, SIGNAL(textChanged(QString)), SLOT(changed(QString)) );
85
86 connect( ui.ui_url, SIGNAL(openFileDialog(KUrlRequester*)), SLOT(slotOpenFileDialog(KUrlRequester*)) );
87}
88
89void InsertFilePanel::slotOpenFileDialog( KUrlRequester * )
90{
91 ui.ui_url->setFilter( "*.plan" );
92}
93
94void InsertFilePanel::changed( const QString &text )
95{
96 emit enableButtonOk( KIO::NetAccess::exists( KUrl( text ), KIO::NetAccess::SourceSide, 0 ) );
97}
98
99KUrl InsertFilePanel::url() const
100{
101 return ui.ui_url->url();
102}
103
104Node *InsertFilePanel::parentNode() const
105{
106 if ( ui.ui_useProject->isChecked() ) {
107 return &(m_project);
108 }
109 if ( ui.ui_isParent->isChecked() ) {
110 return m_node;
111 }
112 if ( ui.ui_isAfter->isChecked() ) {
113 return m_node->parentNode();
114 }
115 return &(m_project);
116}
117
118Node *InsertFilePanel::afterNode() const
119{
120 if ( ui.ui_isAfter->isChecked() ) {
121 return m_node;
122 }
123 return 0;
124}
125
126
127} //KPlato namespace
128
129#include "kptinsertfiledlg.moc"
130