1 /***************************************************************************
2 kgallerydialog.cpp - description
5 copyright : (C) 2003 by Javier Campos
6 email : javi@asyris.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "kgallerydialog.h"
19 #include "kgallerydialog.moc"
24 #include <kmessagebox.h>
25 #include <kio/netaccess.h>
27 #include <qlineedit.h>
28 #include <qlistview.h>
29 #include <qsplitter.h>
31 #include <qfileinfo.h>
33 KGalleryDialog::KGalleryDialog(QWidget
*parent
, const char *name
)
34 :KGalleryDialogBase(parent
,name
)
39 KGalleryDialog::~KGalleryDialog()
43 /** Open keduca file. This function can open a remote or local url. */
44 bool KGalleryDialog::openFile(const KURL
&url
) {
47 if( KIO::NetAccess::download( url
, tmpFile
, this ) )
49 returnval
=loadFile( tmpFile
);
52 kdDebug()<<"... load successful: "<<_currentURL
.url()<<endl
;
55 KIO::NetAccess::removeTempFile( tmpFile
);
57 kdDebug()<<"FileRead::openFile(): download NOT successful: "<<url
.url()<<endl
;
62 bool KGalleryDialog::loadFile( const QString
&filename
)
64 QDomDocument
doc("document.xml");
68 if(!file
.open(IO_ReadOnly
))
72 doc
.setContent( &file
);
74 if( doc
.doctype().name() != "educagallery" )
77 QDomElement docElem
= doc
.documentElement();
78 QDomNode n
= docElem
.firstChild();
80 kdDebug()<<"... load attributes: "<< docElem
.tagName() <<endl
;
82 QDomNodeList dnList
= n
.childNodes();
83 for( unsigned int i
= 0; i
< dnList
.count(); ++i
)
85 QListViewItem
*newItem
= new QListViewItem(listDocuments
);
86 QDomElement serversNode
= dnList
.item(i
).toElement();
88 kdDebug()<<"... load attributes: "<< serversNode
.text() <<endl
;
90 newItem
->setText( 0, serversNode
. text() );
91 newItem
->setText( 1, serversNode
.attribute( "language" ) );
92 newItem
->setText( 2, serversNode
.attribute( "category" ) );
93 newItem
->setText( 3, serversNode
.attribute( "type" ) );
94 newItem
->setText( 4, serversNode
.attribute( "author" ) );
95 newItem
->setText( 5, serversNode
.attribute( "address" ) );
96 newItem
->setSelected(false);
105 void KGalleryDialog::configRead()
107 KConfig
*appconfig
= KGlobal::config();
109 QStringList ipservers
;
110 QStringList::Iterator it_ipservers
;
112 appconfig
->setGroup( "kgallerydialog" );
113 _split
->setSizes( appconfig
->readIntListEntry("Splitter_size") );
114 QSize
defaultSize(500,400);
115 resize( appconfig
->readSizeEntry("Geometry", &defaultSize
) );
117 appconfig
->setGroup("Galleries Servers");
118 servers
= appconfig
->readListEntry ( "Servers" );
119 ipservers
= appconfig
->readListEntry ( "ServersIP" );
121 if( ipservers
.count() == 0 )
123 servers
.append( "KEduca Main Server" );
124 ipservers
.append( "http://keduca.sourceforge.net/gallery/gallery.edugallery" );
127 it_ipservers
=ipservers
.begin();
128 for ( QStringList::Iterator it_servers
= servers
.begin(); it_servers
!= servers
.end(); ++it_servers
)
130 QListViewItem
*newItem
= new QListViewItem(listServers
);
131 newItem
->setText(0,*it_servers
);
132 newItem
->setText(1,*it_ipservers
);
133 newItem
->setSelected(false);
138 /** Write servers lists */
139 void KGalleryDialog::configWrite()
142 QStringList ipservers
;
143 KConfig
*config
= KGlobal::config();
145 config
->setGroup( "kgallerydialog" );
146 config
->writeEntry("Splitter_size", _split
->sizes() );
147 config
->writeEntry("Geometry", size() );
150 config
->setGroup("Galleries Servers");
151 QListViewItem
*item
= listServers
->firstChild();
153 servers
.append( item
->text(0) );
154 ipservers
.append( item
->text(1) );
155 item
= item
->nextSibling();
157 config
->writeEntry("Servers", servers
);
158 config
->writeEntry("ServersIP", ipservers
);
163 /** No descriptions */
164 void KGalleryDialog::slotButtonAdd()
166 if( (lineName
->text()).isEmpty() || (lineAddress
->text()).isEmpty() )
168 KMessageBox::sorry(this, i18n("You need to specify a server!"));
172 QListViewItem
*newItem
= new QListViewItem(listServers
);
173 newItem
->setText(0,lineName
->text());
174 newItem
->setText(1,lineAddress
->text());
175 newItem
->setSelected(false);
178 /** Open selected document */
179 void KGalleryDialog::accept()
181 if (getURL().isEmpty())
182 KMessageBox::sorry(this, i18n("You need to specify the file to open!"));
186 KGalleryDialogBase::accept();
188 // done( QDialog::Accepted );
192 void KGalleryDialog::slotServerSelected( QListViewItem
*item
)
197 KURL url_server
= KURL( item
->text(1) );
199 listDocuments
->clear();
200 openFile( url_server
);
203 /** Get keduca test url */
204 KURL
KGalleryDialog::getURL()
206 QListViewItem
*item
= listDocuments
->currentItem();
211 QString urlAddress
= item
->text(5);
213 if( _currentURL
.isLocalFile() && !KURL(urlAddress
).isValid() )
215 if( !QFileInfo(urlAddress
).exists() )
216 urlAddress
= _currentURL
.directory(false,true) + urlAddress
;
217 kdDebug()<< "Imagen en local" <<endl
;
218 } else if( !_currentURL
.isLocalFile() && !KURL(urlAddress
).isValid() )
219 urlAddress
= _currentURL
.protocol() + "://" + _currentURL
.host() + _currentURL
.directory(false,true) + urlAddress
;
221 kdDebug()<< urlAddress
<<endl
;
222 return KURL( urlAddress
);
226 void KGalleryDialog::putURL(const KURL
&urlFile
)
228 QListViewItem
*newItem
= new QListViewItem(listServers
);
229 newItem
->setText( 1, urlFile
.url() );
230 newItem
->setSelected(false);