summaryrefslogtreecommitdiffstats
path: root/keduca/libkeduca
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 (patch)
treed3bb9f5d25a2dc09ca81adecf39621d871534297 /keduca/libkeduca
downloadtdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.tar.gz
tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'keduca/libkeduca')
-rw-r--r--keduca/libkeduca/Makefile.am10
-rw-r--r--keduca/libkeduca/fileread.cpp999
-rw-r--r--keduca/libkeduca/fileread.h274
-rw-r--r--keduca/libkeduca/kgallerydialog.cpp231
-rw-r--r--keduca/libkeduca/kgallerydialog.h70
-rw-r--r--keduca/libkeduca/kgallerydialogbase.ui370
6 files changed, 1954 insertions, 0 deletions
diff --git a/keduca/libkeduca/Makefile.am b/keduca/libkeduca/Makefile.am
new file mode 100644
index 00000000..f3424f00
--- /dev/null
+++ b/keduca/libkeduca/Makefile.am
@@ -0,0 +1,10 @@
+INCLUDES=$(all_includes)
+
+noinst_LTLIBRARIES = libkeduca.la
+libkeduca_la_SOURCES = kgallerydialogbase.ui fileread.cpp kgallerydialog.cpp
+libkeduca_la_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+libkeduca_la_LIBADD = -lkdeprint
+noinst_HEADERS = fileread.h kgallerydialog.h kgallerydialogbase.h
+
+METASOURCES=AUTO
+include ../../admin/Doxyfile.am
diff --git a/keduca/libkeduca/fileread.cpp b/keduca/libkeduca/fileread.cpp
new file mode 100644
index 00000000..db8f56cb
--- /dev/null
+++ b/keduca/libkeduca/fileread.cpp
@@ -0,0 +1,999 @@
+/***************************************************************************
+ fileread.cpp - description
+ -------------------
+ begin : Wed May 23 2001
+ copyright : (C) 2001 by Javier Campos
+ email : javi@asyris.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 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "fileread.h"
+
+#include <assert.h>
+
+#include <kio/netaccess.h>
+#include <kstandarddirs.h>
+#include <kmimetype.h>
+#include <kdebug.h>
+#include <ktempfile.h>
+
+#include <qfileinfo.h>
+#include <qpixmap.h>
+#include <qbuffer.h>
+
+FileRead::FileRead( QObject *parent, const char *name )
+ :QObject(parent, name),
+ _changed(false),
+ _tmpfile(0)
+{
+}
+
+FileRead::~FileRead()
+{
+}
+
+bool FileRead::openFile(const KURL &url) {
+ QString tmpFile;
+ bool returnval=false;
+ if( KIO::NetAccess::download( url, tmpFile, 0 ) )
+ {
+ returnval=loadFile( tmpFile );
+ if (returnval) {
+ _currentURL = url;
+ kdDebug()<<"... load successful: "<<_currentURL.url()<<endl;
+ }
+
+ KIO::NetAccess::removeTempFile( tmpFile );
+ }else
+ kdDebug()<<"FileRead::openFile(): download NOT successful: "<<url.url()<<endl;
+
+ return returnval;
+}
+
+bool FileRead::loadFile(const QString &filename)
+{
+ QDomDocument doc("document.xml");
+
+ KMimeType::Ptr type = KMimeType::findByFileContent(filename);
+
+ kdDebug() << "FileRead::loadFile(): MIME-Type is " << type->name() << endl;
+
+ QFile file(filename);
+
+ if(!file.open(IO_ReadOnly))
+ {
+ return false;
+ }
+
+ if (type->name() == "text/html") // Non-compressed files are recognized as HTML...
+ {
+ doc.setContent(&file);
+ }
+ else
+ {
+ doc.setContent(qUncompress(file.readAll()));
+ }
+
+ QDomElement docElem = doc.documentElement();
+ if( (doc.doctype().isNull()) || (doc.doctype().name() != "educa") ) {
+ file.close();
+ return false;
+ }
+
+ QDomNode n = docElem.firstChild();
+
+ QDomNodeList dnList = n.childNodes();
+ for( unsigned int i = 0; i < dnList.count(); ++i)
+ {
+ // ------------------- INFORMATION BODY -----------------------
+ QDomElement element = dnList.item(i).toElement();
+ if( element.tagName() == "default" || element.tagName() == "author" )
+ {
+ if( element.tagName() == "default" ) { _header.insert( "image", element.attribute( "image", "default.png" ) ); }
+ if( element.tagName() == "author" ) {
+ QDomNodeList AuthordnList = element.childNodes();
+ for( unsigned int i = 0; i < AuthordnList.count(); ++i) {
+ QDomElement authorelement = AuthordnList.item(i).toElement();
+ _header.insert( authorelement.tagName(), authorelement.text() );
+ }
+ }
+ } else {
+ _header.insert( element.tagName(), element.text() );
+ }
+ }
+
+ n = n.nextSibling();
+
+ dnList = n.childNodes();
+ for( unsigned int i = 0; i < dnList.count(); ++i)
+ {
+ insertQuestion();
+ // --------------------- QUESTION ATTRIBUTE------------------------
+ QDomElement elementNODE = dnList.item(i).toElement();
+ setQuestion( QF_TYPE, elementNODE.attribute( "type", "1" ).toInt() );
+ setQuestion( QF_PICTURE, elementNODE.attribute( "image", "" ) );
+ setQuestion( QF_TIME, elementNODE.attribute( "time", "0" ).toInt() );
+ setQuestion( QF_POINTS, elementNODE.attribute( "points", "0" ).toInt() );
+
+ QDomNodeList quList = elementNODE.childNodes();
+ for( unsigned int x = 0; x < quList.count(); ++x)
+ {
+ // --------------------- QUESTION AND RESPONSES------------------
+ QDomElement element = quList.item(x).toElement();
+ if( element.tagName() == "text" ) setQuestion( QF_TEXT, element.text() );
+ if( element.tagName() == "true" ) setAnswer( element.text(), true, element.attribute( "points", "0" ).toInt() );
+ if( element.tagName() == "false" ) setAnswer( element.text(), false,element.attribute( "points", "0" ).toInt() );
+ if( element.tagName() == "tip" ) setQuestion( QF_TIP, element.text() );
+ if( element.tagName() == "explain" ) setQuestion( QF_EXPLAIN, element.text() );
+ }
+ }
+
+ n = n.nextSibling();
+
+ dnList = n.childNodes();
+
+ if( dnList.count() > 0 )
+ {
+ for( unsigned int i = 0; i < dnList.count(); ++i)
+ {
+ insertResult();
+ // --------------------- QUESTION ATTRIBUTE------------------------
+ QDomElement elementNODE = dnList.item(i).toElement();
+ setResult( RS_TEXT, elementNODE.text() );
+ setResult( RS_PICTURE, elementNODE.attribute( "image", "" ) );
+ setResult( RS_MIN, elementNODE.attribute( "min", "0" ).toInt() );
+ setResult( RS_MAX, elementNODE.attribute( "max", "0" ).toInt() );
+ }
+ }
+
+ file.close();
+
+ refreshData();
+
+ _changed=false;
+ return true;
+}
+
+void FileRead::setQuestion( QuestionField field, const QString& text)
+{
+// QF_text, QF_picture, QF_type, QF_time, QF_tip, QF_explain
+ switch( field )
+ {
+ case QF_TEXT:
+ (*_recordQuestions).text = text;
+ break;
+ case QF_PICTURE:
+ (*_recordQuestions).picture = text;
+ break;
+ case QF_TIP:
+ (*_recordQuestions).tip = text;
+ break;
+ case QF_EXPLAIN:
+ (*_recordQuestions).explain = text;
+ break;
+ default:
+ kdDebug()<<"FileRead::setQuestion(QuestionField field, QString text) called for not handled field value "<<field <<endl;
+ break;
+ }
+ _changed=true;
+}
+
+void FileRead::setQuestion( QuestionField field, int value )
+{
+ switch( field )
+ {
+ case QF_TYPE:
+ (*_recordQuestions).type = value;
+ break;
+ case QF_TIME:
+ (*_recordQuestions).time = value;
+ break;
+ case QF_POINTS:
+ (*_recordQuestions).points = value;
+ break;
+ default:
+ kdDebug()<<"FileRead::setQuestion(QuestionField field, int value) called for not handled field value "<<field <<endl;
+ break;
+ }
+ _changed=true;
+}
+
+void FileRead::setResult( ResultField field, const QString& text)
+{
+// RS_text, QF_picture
+ switch( field )
+ {
+ case RS_TEXT:
+ (*_recordResults).text = text;
+ break;
+ case RS_PICTURE:
+ (*_recordResults).picture = text;
+ break;
+ default:
+ kdDebug()<<"FileRead::setResult(ResultField field, QString text) called for not handled field value "<<field <<endl;
+ break;
+ }
+ _changed=true;
+}
+
+void FileRead::setResult( ResultField field, int value )
+{
+ switch( field )
+ {
+ case RS_MIN:
+ (*_recordResults).min = value;
+ break;
+ case RS_MAX:
+ (*_recordResults).max = value;
+ break;
+ default:
+ kdDebug()<<"FileRead::setResultInt(ResultField field, int value) called for not handled field value "<<field <<endl;
+ break;
+ }
+ _changed=true;
+}
+
+void FileRead::setAnswer( const QString& text, bool value, int points)
+{
+ Answers tmpAnswers;
+
+ tmpAnswers.text = text;
+ tmpAnswers.value = value;
+ tmpAnswers.points = points;
+
+ (*_recordQuestions).listAnswers.append( tmpAnswers );
+ _changed=true;
+}
+
+void FileRead::insertQuestion()
+{
+ Questions tempQuestions;
+ tempQuestions.text = "";
+ _listQuestions.append( tempQuestions );
+ recordLast();
+ _changed=true;
+}
+
+void FileRead::insertResult()
+{
+ Results tempResults;
+ tempResults.text = "";
+ _listResults.append( tempResults );
+ recordResultLast();
+ _changed=true;
+}
+
+void FileRead::recordFirst()
+{
+ if( _fileEOF = true ) _fileEOF = false;
+ if( _fileBOF = false ) _fileBOF = true;
+ _recordQuestions = _listQuestions.begin();
+}
+
+void FileRead::recordLast()
+{
+ if( _fileBOF = true ) _fileBOF = false;
+ if( _fileEOF = false ) _fileEOF = true;
+ _recordQuestions = _listQuestions.end();
+ --_recordQuestions;
+}
+
+void FileRead::recordNext()
+{
+ ++_recordQuestions;
+ if( _recordQuestions == _listQuestions.end() )
+ {
+ _fileEOF = true;
+ --_recordQuestions;
+ }
+ else
+ if( _fileBOF = true ) _fileBOF = false;
+}
+
+void FileRead::recordPrevious()
+{
+ if( _recordQuestions == _listQuestions.begin() )
+ _fileBOF = true;
+ else
+ {
+ if( _fileEOF = true ) _fileEOF = false;
+ --_recordQuestions;
+ }
+}
+
+void FileRead::recordResultFirst()
+{
+ if( _fileResultEOF = true ) _fileResultEOF = false;
+ if( _fileResultBOF = false ) _fileResultBOF = true;
+ _recordResults = _listResults.begin();
+}
+
+void FileRead::recordResultLast()
+{
+ if( _fileResultBOF = true ) _fileResultBOF = false;
+ if( _fileResultEOF = false ) _fileResultEOF = true;
+ _recordResults = _listResults.end();
+ --_recordResults;
+}
+
+void FileRead::recordResultNext()
+{
+ ++_recordResults;
+ if( _recordResults == _listResults.end() )
+ {
+ _fileResultEOF = true;
+ --_recordResults;
+ }
+ else
+ {
+ if( _fileBOF = true ) _fileBOF = false;
+ }
+}
+
+void FileRead::recordResultPrevious()
+{
+ if( _recordResults == _listResults.begin() )
+ {
+ _fileResultBOF = true;
+ }
+ else
+ {
+ if( _fileResultEOF = true ) _fileResultEOF = false;
+ --_recordResults;
+ }
+}
+
+void FileRead::recordAnswerFirst()
+{
+ if( _fileAnswerEOF = true ) _fileAnswerEOF = false;
+ if( _fileAnswerBOF = false ) _fileAnswerBOF = true;
+ (*_recordQuestions).recordAnswers = (*_recordQuestions).listAnswers.begin();
+}
+
+void FileRead::recordAnswerLast()
+{
+ if( _fileAnswerBOF = true ) _fileAnswerBOF = false;
+ if( _fileAnswerEOF = false ) _fileAnswerEOF = true;
+ (*_recordQuestions).recordAnswers = (*_recordQuestions).listAnswers.end();
+ --(*_recordQuestions).recordAnswers;
+}
+
+void FileRead::recordAnswerNext()
+{
+ ++(*_recordQuestions).recordAnswers;
+ if( (*_recordQuestions).recordAnswers == (*_recordQuestions).listAnswers.end() )
+ {
+ _fileAnswerEOF = true;
+ --(*_recordQuestions).recordAnswers;
+ }
+ else
+ {
+ if( _fileAnswerBOF = true ) _fileAnswerBOF = false;
+ }
+}
+
+void FileRead::recordAnswerPrevious()
+{
+ if( (*_recordQuestions).recordAnswers == (*_recordQuestions).listAnswers.begin() )
+ {
+ _fileBOF = true;
+ }
+ else
+ {
+ if( _fileAnswerEOF = true ) _fileAnswerEOF = false;
+ --(*_recordQuestions).recordAnswers;
+ }
+}
+
+void FileRead::recordAnswerAt( unsigned int index)
+{
+ (*_recordQuestions).recordAnswers = (*_recordQuestions).listAnswers.begin();
+ for( unsigned int i = 0; i < index; ++i)
+ ++(*_recordQuestions).recordAnswers;
+}
+
+unsigned int FileRead::recordAnswerCount()
+{
+ return (*_recordQuestions).listAnswers.count();
+}
+
+QString FileRead::getQuestion( QuestionField field )
+{
+// QF_text, QF_picture, QF_type, QF_time, QF_tip, QF_explain
+ switch( field )
+ {
+ case QF_TEXT:
+ return (*_recordQuestions).text;
+ break;
+ case QF_PICTURE:
+// return getPictureLocal( (*_recordQuestions).picture );
+ return( (*_recordQuestions).picture );
+ break;
+ case QF_POINTS:
+ return QString().setNum( (*_recordQuestions).points );
+ break;
+ case QF_TIME:
+ return QString().setNum( (*_recordQuestions).time );
+ break;
+ case QF_TIP:
+ return (*_recordQuestions).tip;
+ break;
+ case QF_EXPLAIN:
+ return (*_recordQuestions).explain;
+ break;
+ default:
+ kdDebug()<<"FileRead::getQuestion() called for not handled field value "<<field <<endl;
+ return "";
+ break;
+ }
+}
+
+int FileRead::getQuestionInt( QuestionField field )
+{
+ switch( field )
+ {
+ case QF_TYPE:
+ return (*_recordQuestions).type;
+ break;
+ case QF_TIME:
+ return (*_recordQuestions).time;
+ break;
+ case QF_POINTS:
+ return (*_recordQuestions).points;
+ break;
+ default:
+ kdDebug()<<"FileRead::getQuestionInt() called for not handled field value "<<field <<endl;
+ return 0;
+ }
+}
+
+QString FileRead::getAnswer( AnswerField field )
+{
+ // AField { AF_text, AF_value, AF_picture, AF_point };
+ switch( field )
+ {
+ case AF_TEXT:
+ return (*(*_recordQuestions).recordAnswers).text;
+ break;
+// case AF_VALUE:
+// (*(*_recordQuestions).RecordAnswers).Value ? return i18n("True") : return i18n("False");
+// break;
+ case AF_POINT:
+ return QString().setNum( (*(*_recordQuestions).recordAnswers).points );
+ break;
+ default:
+ kdDebug()<<"FileRead::getAnswer() called for not handled field value "<<field <<endl;
+ return "";
+ }
+}
+
+bool FileRead::getAnswerValue()
+{
+ return (*(*_recordQuestions).recordAnswers).value;
+}
+
+int FileRead::getAnswerPoints()
+{
+ return (*(*_recordQuestions).recordAnswers).points;
+}
+
+QString FileRead::getResult( ResultField field )
+{
+ switch( field )
+ {
+ case RS_TEXT:
+ return (*_recordResults).text;
+ break;
+ case RS_PICTURE:
+ return( (*_recordResults).picture );
+ break;
+ case RS_MIN:
+ return QString().setNum( (*_recordResults).min );
+ break;
+ case RS_MAX:
+ return QString().setNum( (*_recordResults).max );
+ break;
+ default:
+ kdDebug()<<"FileRead::getResult() called for not handled field value "<<field <<endl;
+ return "";
+ break;
+ }
+}
+
+int FileRead::getResultInt( ResultField field )
+{
+ switch( field )
+ {
+ case RS_MIN:
+ return (*_recordResults).min;
+ break;
+ case RS_MAX:
+ return (*_recordResults).max;
+ break;
+ default:
+ kdDebug()<<"FileRead::getResult() called for not handled field value "<<field <<endl;
+ return 0;
+ break;
+ }
+}
+
+bool FileRead::recordEOF()
+{
+ return _fileEOF;
+}
+
+bool FileRead::recordBOF()
+{
+ return _fileBOF;
+}
+
+bool FileRead::recordResultEOF()
+{
+ return _fileResultEOF;
+}
+
+bool FileRead::recordResultBOF()
+{
+ return _fileResultBOF;
+}
+
+bool FileRead::recordAnswerEOF()
+{
+ return _fileAnswerEOF;
+}
+
+bool FileRead::recordAnswerBOF()
+{
+ return _fileAnswerBOF;
+}
+
+QString FileRead::getPicture()
+{
+ QString picture;
+
+ if( !getQuestion(QF_PICTURE).isEmpty() )
+ picture = getQuestion(QF_PICTURE);
+ else if( !(_header["image"]).isEmpty() )
+ picture = _header["image"];
+ else
+ return locate("data","keduca/pics/default.png");
+
+ if( _currentURL.isLocalFile() && !KURL(picture).isValid() )
+ {
+ if( !QFileInfo(picture).exists() )
+ picture = _currentURL.directory(false,true) + picture;
+ } else if( !_currentURL.isLocalFile() && !KURL(picture).isValid() )
+ picture = _currentURL.protocol() + "://" + _currentURL.host() + _currentURL.directory(false,true) + picture;
+
+ kdDebug()<< picture <<endl;
+
+ return picture;
+}
+
+QPixmap FileRead::getPicturePixmap()
+{
+
+ KURL picture ( getPicture() );
+ QPixmap pict;
+
+ if( KIO::NetAccess::download( picture, _tmpfileImage, 0 ) )
+ {
+ kdDebug()<<"... load successful: "<< _tmpfileImage <<endl;
+ pict = QPixmap( _tmpfileImage );
+ KIO::NetAccess::removeTempFile( _tmpfileImage );
+ }
+ else
+ {
+ kdDebug()<<"FileRead::openFile(): download NOT successful: "<< _tmpfileImage <<endl;
+ pict = NULL;
+ }
+
+ return pict;
+}
+
+void FileRead::clearAnswers()
+{
+ ((*_recordQuestions).listAnswers).clear();
+ _changed=true;
+}
+
+void FileRead::recordDelete()
+{
+ _listQuestions.remove( _recordQuestions );
+ _changed=true;
+}
+
+void FileRead::recordSwap( bool moveup )
+{
+ Questions listTMP;
+ Questions listNEW;
+
+ listTMP = (*_recordQuestions);
+
+ if( moveup )
+ {
+ recordPrevious();
+ listNEW = (*_recordQuestions);
+ (*_recordQuestions) = listTMP;
+ recordNext();
+ (*_recordQuestions) = listNEW;
+ }
+ else
+ {
+ recordNext();
+ listNEW = (*_recordQuestions);
+ (*_recordQuestions) = listTMP;
+ recordPrevious();
+ (*_recordQuestions) = listNEW;
+ }
+ _changed=true;
+}
+
+bool FileRead::saveFile( const KURL &url, bool copyimages, bool saveCompressed )
+{
+ if (url.isValid())
+ {
+ _currentURL = url;
+ }
+ kdDebug()<<"FileRead::saveFile() to "<<_currentURL.url()<<endl;
+ // Local file
+ if ( _currentURL.isLocalFile() )
+ {
+ if ( _tmpfile != 0 ) // get rid of a possible temp file first
+ { // (happens if previous _currentURL was remote)
+ _tmpfile->unlink();
+ delete _tmpfile;
+ _tmpfile = 0;
+ }
+ if( saveFile(_currentURL.path(), copyimages, saveCompressed) ) {
+ emit completed();
+ emit setWindowCaption( _currentURL.prettyURL() );
+ return true;
+ }
+ }
+ else
+ { // Remote file
+ // We haven't saved yet, or we did but locally - provide a temp file
+ if ( _tmpfile == 0 )
+ {
+ _tmpfile = new KTempFile;
+ }
+ // otherwise, we already had a temp file
+ if( saveFile(_tmpfile->name(), copyimages, saveCompressed) ) {
+ // upload the file
+ KIO::Job * job = KIO::file_copy( KURL::fromPathOrURL( _tmpfile->name() ), _currentURL, -1, true /*overwrite*/ );
+ connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotUploadFinished (KIO::Job *) ) );
+ return true;
+ }
+ }
+
+ // Save local file and upload local file
+ return false;
+}
+
+bool FileRead::saveFile( const QString &filename, bool copyimages, bool saveCompressed )
+{
+ QDomDocument doc("document.xml");
+ QTextStream stream;
+ QString line;
+ QByteArray data;
+ QBuffer buffer(data);
+ QFile file(filename);
+ QStringList copyJOB;
+
+ stream.setDevice(&buffer);
+
+ if ( (!file.open(IO_WriteOnly)) || (!buffer.open(IO_WriteOnly)) )
+ {
+ return false;
+ }
+ /*
+ stream.setDevice(&file);
+
+ if(!file.open(IO_WriteOnly))
+ {
+ // No puede abrir la base
+ return false;
+ }
+ */
+
+ QString head( "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><!DOCTYPE educa>" );
+ doc.setContent( head );
+
+ QDomElement Root = doc.createElement("Document");
+ doc.appendChild( Root );
+
+ QDomElement NodeInfo = doc.createElement("Info");
+ Root.appendChild( NodeInfo );
+
+ insertXML( doc, NodeInfo, "title", _header["title"] );
+ insertXML( doc, NodeInfo, "category", _header["category"] );
+ insertXML( doc, NodeInfo, "type", _header["type"] );
+ insertXML( doc, NodeInfo, "level", _header["level"] );
+ insertXML( doc, NodeInfo, "language", _header["language"] );
+
+ if( !(_header["image"]).isEmpty() )
+ {
+ QDomElement Nodedefault = doc.createElement("default");
+
+ if( copyimages )
+ {
+ copyJOB.append( _header["image"] );
+ Nodedefault.setAttribute( "image", QFileInfo(_header["image"]).fileName() );
+ } else {
+ Nodedefault.setAttribute( "image", _header["image"]);
+ }
+ NodeInfo.appendChild( Nodedefault );
+ }
+
+ if( !_header["name"].isEmpty() || !_header["email"].isEmpty() || !_header["www"].isEmpty() )
+ {
+ QDomElement Nodeauthor = doc.createElement("author");
+ NodeInfo.appendChild( Nodeauthor );
+ if( !_header["name"].isEmpty() ) insertXML( doc, Nodeauthor, "name", _header["name"] );
+ if( !_header["email"].isEmpty() ) insertXML( doc, Nodeauthor, "email", _header["email"] );
+ if( !_header["www"].isEmpty() ) insertXML( doc, Nodeauthor, "www", _header["www"] );
+ }
+
+ QDomElement NodeData = doc.createElement("Data");
+ Root.appendChild( NodeData );
+
+ recordFirst();
+ while ( !recordEOF() )
+ {
+ QDomElement question = doc.createElement("question");
+ if( !getQuestion( QF_PICTURE ).isEmpty() )
+ {
+ if( copyimages )
+ {
+ copyJOB.append( getQuestion( QF_PICTURE ) );
+ question.setAttribute("image", QFileInfo( getQuestion( QF_PICTURE ) ).fileName() );
+ } else {
+ question.setAttribute("image", getQuestion( QF_PICTURE ) );
+ }
+ }
+ question.setAttribute( "type", getQuestionInt( QF_TYPE ) );
+ if( getQuestionInt( QF_POINTS ) > 0 ) question.setAttribute( "points", getQuestion( QF_POINTS ) );
+ if( getQuestionInt( QF_TIME ) > 0 ) question.setAttribute( "time", getQuestion( QF_TIME ) );
+ insertXML( doc, question, "text", getQuestion( QF_TEXT ) );
+
+ recordAnswerFirst();
+ while( !recordAnswerEOF() )
+ {
+ if( getAnswerValue() )
+ {
+ QDomElement domELEMENT = doc.createElement( "true" );
+ if( getAnswerPoints() > 0 ) domELEMENT.setAttribute("points", getAnswerPoints() );
+ QDomText DATAelement = doc.createTextNode( getAnswer( AF_TEXT ) );
+ question.appendChild( domELEMENT );
+ domELEMENT.appendChild( DATAelement );
+ } else {
+// insertXML( doc, question, "false", getAnswer( AF_text ) );
+ QDomElement domELEMENT = doc.createElement( "false" );
+ if( getAnswerPoints() > 0 ) domELEMENT.setAttribute("points", getAnswerPoints() );
+ QDomText DATAelement = doc.createTextNode( getAnswer( AF_TEXT ) );
+ question.appendChild( domELEMENT );
+ domELEMENT.appendChild( DATAelement );
+ }
+ recordAnswerNext();
+ };
+
+ if( !getQuestion( QF_TIP ).isEmpty() ) insertXML( doc, question, "tip", getQuestion( QF_TIP ) );
+ if( !getQuestion( QF_EXPLAIN ).isEmpty() ) insertXML( doc, question, "explain", getQuestion( QF_EXPLAIN ) );
+
+ NodeData.appendChild( question );
+ recordNext();
+ }
+
+ doc.save( stream, 4);
+ buffer.close();
+ if ( saveCompressed )
+ file.writeBlock(qCompress(data));
+ else
+ file.writeBlock(data);
+ file.close();
+
+ if( copyimages == true && copyJOB.count() > 0 )
+ {
+ KURL::List KurlLIST( copyJOB );
+ KIO::CopyJob *copyjob;
+
+ copyjob = KIO::copy( KurlLIST, KURL( _currentURL.directory(false,true) ), true);
+ }
+ _changed=false;
+ return true;
+
+}
+
+/** Save results */
+bool FileRead::saveResults( const KURL &url, const QString &results )
+{
+ if (url.isValid())
+ {
+ _currentURL = url;
+ }
+ kdDebug()<<"FileRead::saveResults() to "<<_currentURL.url()<<endl;
+ // Local file
+ if ( _currentURL.isLocalFile() )
+ {
+ if ( _tmpfile != 0 ) // get rid of a possible temp file first
+ { // (happens if previous _currentURL was remote)
+ _tmpfile->unlink();
+ delete _tmpfile;
+ _tmpfile = 0;
+ }
+ if( saveResults(_currentURL.path(), results) ) {
+ emit completed();
+ emit setWindowCaption( _currentURL.prettyURL() );
+ return true;
+ }
+ }
+ else
+ { // Remote file
+ // We haven't saved yet, or we did but locally - provide a temp file
+ if ( _tmpfile == 0 )
+ {
+ _tmpfile = new KTempFile;
+ }
+ // otherwise, we already had a temp file
+ if( saveResults(_tmpfile->name(), results) ) {
+ // upload the file
+ KIO::Job * job = KIO::file_copy( KURL::fromPathOrURL( _tmpfile->name() ), _currentURL, -1, true /*overwrite*/ );
+ connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotUploadFinished (KIO::Job *) ) );
+ return true;
+ }
+ }
+
+ // Save local file and upload local file
+ return false;
+}
+
+bool FileRead::saveResults( const QString &filename, const QString &results )
+{
+ QTextStream stream;
+ QFile file(filename);
+ QStringList copyJOB;
+
+ stream.setDevice(&file);
+
+ if(!file.open(IO_WriteOnly))
+ {
+ // Cannot open
+ return false;
+ }
+ stream << results;
+ file.close();
+ return true;
+}
+
+/** Insert xml format data */
+void FileRead::insertXML( QDomDocument &doc, QDomElement &parent, const QString &tagName, const QString &data)
+{
+ QDomElement domELEMENT = doc.createElement( tagName );
+ QDomText DATAelement = doc.createTextNode( data );
+
+ parent.appendChild( domELEMENT );
+ domELEMENT.appendChild( DATAelement );
+}
+
+/** Insert xml data format */
+void FileRead::insertXML( QDomDocument &doc, QDomElement &parent, const QString &data)
+{
+ QDomText DATAelement = doc.createTextNode( data );
+ parent.appendChild( DATAelement );
+}
+
+/** Get Header */
+QString FileRead::getHeader(const QString &head)
+{
+ return _header[head];
+}
+
+/** Set header data */
+void FileRead::setHeader( const QString field, const QString value)
+{
+ _changed = _header[field]!=value;
+
+ if( (_header[field]).isEmpty() )
+ _header.insert( field, value );
+ else
+ _header.replace( field, value );
+}
+
+/** is Multi Answer */
+bool FileRead::isMultiAnswer()
+{
+ int numOKanswer = 0;
+
+ recordAnswerFirst();
+
+ while( !recordAnswerEOF() )
+ {
+ if( (*(*_recordQuestions).recordAnswers).value == true ) numOKanswer++;
+ recordAnswerNext();
+ }
+
+ if( numOKanswer > 1 ) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/** is Multi Answer */
+bool FileRead::isResult()
+{
+ return _listResults.count() > 0 ? true : false;
+}
+
+void FileRead::slotUploadFinished( KIO::Job * job )
+{
+ if (job->error()) {
+ emit canceled( job->errorString() );
+ kdDebug()<< "FileRead::slotUploadFinished(): " <<job->errorString()<<endl;
+ }
+ else
+ {
+ if ( _tmpfile!=0 ) // We're finished with this document -> remove temp file
+ {
+ _tmpfile->unlink();
+ delete _tmpfile;
+ _tmpfile=0;
+ }
+ emit setWindowCaption( _currentURL.prettyURL() );
+ emit completed();
+ }
+}
+
+/** Record at index */
+void FileRead::recordAt( uint index )
+{
+ _recordQuestions = _listQuestions.begin();
+ for( unsigned int i = 0; i < index; ++i)
+ ++_recordQuestions;
+}
+
+/** Total questions */
+uint FileRead::getTotalQuestions()
+{
+ return _totalQuestions;
+}
+
+/** Total points */
+uint FileRead::getTotalPoints()
+{
+ return _totalPoints;
+}
+
+/** Total time */
+uint FileRead::getTotalTime()
+{
+ return _totalTime;
+}
+
+/** Refresh stadistical data - Points, number questions and total points */
+void FileRead::refreshData()
+{
+ _totalTime = 0;
+ _totalPoints = 0;
+ _totalQuestions = 0;
+
+ _recordQuestions = _listQuestions.begin();
+ while ( _recordQuestions != _listQuestions.end() )
+ {
+ _totalQuestions++;
+ _totalPoints += (*_recordQuestions).points;
+ _totalTime += (*_recordQuestions).time;
+ ++_recordQuestions;
+ }
+}
+
+#include "fileread.moc"
diff --git a/keduca/libkeduca/fileread.h b/keduca/libkeduca/fileread.h
new file mode 100644
index 00000000..3dc82a0b
--- /dev/null
+++ b/keduca/libkeduca/fileread.h
@@ -0,0 +1,274 @@
+/***************************************************************************
+ fileread.h - description
+ -------------------
+ begin : Wed May 23 2001
+ copyright : (C) 2001 by Javier Campos
+ email : javi@asyris.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 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef FILEREAD_H
+#define FILEREAD_H
+
+#include <kio/job.h>
+
+#include <qdom.h>
+
+// forward declarations
+class KTempFile;
+
+class QFile;
+
+/**File Read operations. This class read a keduca file an pass the records.
+ *@author Javier Campos
+ *@author Klas Kalass
+ */
+
+class FileRead : public QObject {
+ Q_OBJECT
+
+public:
+ FileRead( QObject *parent=0, const char *name=0 );
+ virtual ~FileRead();
+ enum QuestionField { QF_TEXT, QF_PICTURE, QF_POINTS, QF_TYPE, QF_TIME, QF_TIP, QF_EXPLAIN };
+ enum AnswerField { AF_TEXT, AF_VALUE, AF_POINT };
+ enum ResultField { RS_TEXT, RS_MIN, RS_MAX, RS_PICTURE };
+
+ /** Open keduca file. This function can open a remote or local url. */
+ bool openFile( const KURL &url );
+ /** Set value to questions fields */
+ void setQuestion( QuestionField field, const QString& text);
+ /** Set value to questions fields */
+ void setQuestion( QuestionField field, int value );
+ /** Set value to results fields */
+ void setResult( ResultField field, const QString& text);
+ /** Set value to results fields */
+ void setResult( ResultField field, int value );
+ /** Insert an answer field */
+ void setAnswer( const QString& text, bool value, int points=0);
+ /** Go to the Last Record */
+ void recordLast();
+ /** Go to the First record */
+ void recordFirst();
+ /** Go to the Last Record */
+ void recordResultLast();
+ /** Go to the First record */
+ void recordResultFirst();
+ /** Insert a blank question */
+ void insertQuestion();
+ /** Insert a blank result */
+ void insertResult();
+ /** Record Next */
+ void recordNext();
+ /** Record previous */
+ void recordPrevious();
+ /** Record Next */
+ void recordResultNext();
+ /** Record previous */
+ void recordResultPrevious();
+ /** Go to the Last Record */
+ void recordAnswerLast();
+ /** Go to the First record */
+ void recordAnswerFirst();
+ /** Record Next */
+ void recordAnswerNext();
+ /** Record previous */
+ void recordAnswerPrevious();
+ /** Move to record */
+ void recordAnswerAt( unsigned int index);
+ /** Record answer count */
+ unsigned int recordAnswerCount();
+ /** Get the value of the field question */
+ QString getQuestion( QuestionField field );
+ /** Get the value of the field questions in integer */
+ int getQuestionInt( QuestionField field );
+ /** Get Answer field */
+ QString getAnswer( AnswerField field );
+ /** Get answer field */
+ int getAnswerPoints();
+ /** Get Answer field */
+ bool getAnswerValue();
+ /** Get the value of the field result */
+ QString getResult( ResultField field );
+ /** Get the value of the field result */
+ int getResultInt( ResultField field );
+ /** Returns if this record is a begin of file */
+ bool recordBOF();
+ /** Returns if this record is a end of file */
+ bool recordEOF();
+ /** Returns if this record is a begin of file */
+ bool recordResultBOF();
+ /** Returns if this record is a end of file */
+ bool recordResultEOF();
+ /** Returns if this record is a begin of file */
+ bool recordAnswerBOF();
+ /** Returns if this record is a end of file */
+ bool recordAnswerEOF();
+ /** Clear answers */
+ void clearAnswers();
+ /** Delete current record */
+ void recordDelete();
+ /** Swap two variables */
+ void recordSwap( bool );
+ /** Save file */
+ bool saveFile( const KURL &url = KURL(), bool copyimages = false, bool saveCompressed = true );
+ /** Save results */
+ bool saveResults( const KURL &url, const QString &results );
+ /** Get real picture */
+ QString getPicture();
+ /** Get real picture */
+ QPixmap getPicturePixmap();
+ /** Set header data */
+ void setHeader( const QString field, const QString value);
+ /** Get Header */
+ QString getHeader(const QString &head);
+ /** is Multi Answer */
+ bool isMultiAnswer();
+ /** is Result */
+ bool isResult();
+ KURL const &getCurrentURL()const{return _currentURL;}
+ /** @return true: The document has changed and should be saved*/
+ bool changed() {return _changed;}
+ /** Record at index */
+ void recordAt( uint index );
+ /** Refresh stadistical data - Points, number questions and total points */
+ void refreshData();
+ /* get total questions */
+ uint getTotalQuestions();
+ /* get total Points */
+ uint getTotalPoints();
+ /* get total Time */
+ uint getTotalTime();
+private:
+
+ // Private attributes
+
+ bool _changed;
+ /** List of General Variables of the header */
+ QMap<QString,QString> _header;
+
+ struct Answers
+ {
+ QString text;
+ bool value;
+ int points;
+ };
+
+ struct Results
+ {
+ QString text;
+ QString picture;
+ int min;
+ int max;
+ };
+
+ struct Questions
+ {
+ QString text;
+ int type;
+ QString picture;
+ int time;
+ int points;
+ QString tip;
+ QString explain;
+ QValueList<Answers> listAnswers;
+ QValueListIterator<Answers> recordAnswers;
+ };
+
+ /** List to Data struct */
+ QValueList<Questions> _listQuestions;
+ QValueListIterator<Questions> _recordQuestions;
+
+ QValueList<Results> _listResults;
+ QValueListIterator<Results> _recordResults;
+
+ /** Returns if the database finds End Of File */
+ bool _fileEOF;
+ /** Returns if the database finds Bof Of File */
+ bool _fileBOF;
+ /** Returns if the database finds End Of File */
+ bool _fileAnswerEOF;
+ /** Returns if the database finds Bof Of File */
+ bool _fileAnswerBOF;
+ /** Returns if the database finds End Of File */
+ bool _fileResultEOF;
+ /** Returns if the database finds Bof Of File */
+ bool _fileResultBOF;
+ /** Current url */
+ KURL _currentURL;
+ /** the temporary file to which the document is saved, NULL if no temporary file is needed */
+ KTempFile *_tmpfile;
+ /** the temporary image file */
+ QString _tmpfileImage;
+ /** Total Questions */
+ uint _totalQuestions;
+ /** Total Time */
+ uint _totalTime;
+ /** Total Points */
+ uint _totalPoints;
+
+ // Private methods
+
+ /** Insert xml format data */
+ void insertXML( QDomDocument &doc, QDomElement &parent, const QString &tagName, const QString &data);
+ /** Insert xml data format */
+ void insertXML( QDomDocument &doc, QDomElement &parent, const QString &data);
+
+protected:
+ /** Open keduca file. This function does the actual work and expects a local filename . */
+ bool loadFile( const QString &filename );
+ /** Save KEduca file to the file*/
+ bool saveFile( const QString &filename, bool copyimages, bool saveCompressed = true );
+ /** Save Results file to the file */
+ bool saveResults( const QString &filename, const QString &results );
+
+protected slots:
+ void slotUploadFinished( KIO::Job * job );
+
+signals:
+/* Stolen from kparts */
+
+ /**
+ * Emit this when you have completed loading data.
+ * Hosting apps will want to know when the process of loading the data
+ * is finished, so that they can access the data when everything is loaded.
+ **/
+ void completed();
+
+ /**
+ * Same as the above signal except besides indicating that the data has
+ * been completely loaded it also informs the host, by setting the flag,
+ * that a pending action has been generated as a result of completing the
+ * requested task (loading the data). An example of this is meta-refresh
+ * tags on HTML pages which result in the page either being refreshed or
+ * the viewer being redirected to another page. By emitting this signal
+ * after appropriately setting the flag, the part can tell the host of the
+ * pending scheduled action inorder to give it a chance to accept or cancel
+ * that action.
+ *
+ * @p pendingAction if true, a pending action exists (ex: a scheduled refresh)
+ */
+ void completed( bool pendingAction );
+
+ /**
+ * Emit this if loading is canceled by the user or by an error.
+ **/
+ void canceled( const QString &errMsg );
+
+ /**
+ * Emitted by the part, to set the caption of the window(s)
+ * hosting this part
+ */
+ void setWindowCaption( const QString & caption );
+
+};
+
+#endif
diff --git a/keduca/libkeduca/kgallerydialog.cpp b/keduca/libkeduca/kgallerydialog.cpp
new file mode 100644
index 00000000..0ab2d126
--- /dev/null
+++ b/keduca/libkeduca/kgallerydialog.cpp
@@ -0,0 +1,231 @@
+/***************************************************************************
+ kgallerydialog.cpp - description
+ -------------------
+ begin : mar abr 1 2003
+ copyright : (C) 2003 by Javier Campos
+ email : javi@asyris.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 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "kgallerydialog.h"
+#include "kgallerydialog.moc"
+
+#include <kdebug.h>
+#include <kconfig.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kio/netaccess.h>
+
+#include <qlineedit.h>
+#include <qlistview.h>
+#include <qsplitter.h>
+#include <qdom.h>
+#include <qfileinfo.h>
+
+KGalleryDialog::KGalleryDialog(QWidget *parent, const char *name )
+ :KGalleryDialogBase(parent,name)
+{
+ configRead();
+}
+
+KGalleryDialog::~KGalleryDialog()
+{
+}
+
+/** Open keduca file. This function can open a remote or local url. */
+bool KGalleryDialog::openFile(const KURL &url) {
+ QString tmpFile;
+ bool returnval=false;
+ if( KIO::NetAccess::download( url, tmpFile, this ) )
+ {
+ returnval=loadFile( tmpFile );
+ if (returnval) {
+ _currentURL = url;
+ kdDebug()<<"... load successful: "<<_currentURL.url()<<endl;
+ }
+
+ KIO::NetAccess::removeTempFile( tmpFile );
+ }else
+ kdDebug()<<"FileRead::openFile(): download NOT successful: "<<url.url()<<endl;
+
+ return returnval;
+}
+
+bool KGalleryDialog::loadFile( const QString &filename )
+{
+ QDomDocument doc("document.xml");
+
+ QFile file(filename);
+
+ if(!file.open(IO_ReadOnly))
+ {
+ return false;
+ }
+ doc.setContent( &file );
+
+ if( doc.doctype().name() != "educagallery" )
+ { return false; }
+
+ QDomElement docElem = doc.documentElement();
+ QDomNode n = docElem.firstChild();
+
+ kdDebug()<<"... load attributes: "<< docElem.tagName() <<endl;
+
+ QDomNodeList dnList = n.childNodes();
+ for( unsigned int i = 0; i < dnList.count(); ++i)
+ {
+ QListViewItem *newItem = new QListViewItem(listDocuments);
+ QDomElement serversNode = dnList.item(i).toElement();
+
+ kdDebug()<<"... load attributes: "<< serversNode.text() <<endl;
+
+ newItem->setText( 0, serversNode. text() );
+ newItem->setText( 1, serversNode.attribute( "language" ) );
+ newItem->setText( 2, serversNode.attribute( "category" ) );
+ newItem->setText( 3, serversNode.attribute( "type" ) );
+ newItem->setText( 4, serversNode.attribute( "author" ) );
+ newItem->setText( 5, serversNode.attribute( "address" ) );
+ newItem->setSelected(false);
+ }
+
+ file.close();
+
+ return true;
+}
+
+/** Read servers */
+void KGalleryDialog::configRead()
+{
+ KConfig *appconfig = KGlobal::config();
+ QStringList servers;
+ QStringList ipservers;
+ QStringList::Iterator it_ipservers;
+
+ appconfig->setGroup( "kgallerydialog" );
+ _split->setSizes( appconfig->readIntListEntry("Splitter_size") );
+ QSize defaultSize(500,400);
+ resize( appconfig->readSizeEntry("Geometry", &defaultSize ) );
+
+ appconfig->setGroup("Galleries Servers");
+ servers = appconfig->readListEntry ( "Servers" );
+ ipservers = appconfig->readListEntry ( "ServersIP" );
+
+ if( ipservers.count() == 0 )
+ {
+ servers.append( "KEduca Main Server" );
+ ipservers.append( "http://keduca.sourceforge.net/gallery/gallery.edugallery" );
+ }
+
+ it_ipservers=ipservers.begin();
+ for ( QStringList::Iterator it_servers = servers.begin(); it_servers != servers.end(); ++it_servers )
+ {
+ QListViewItem *newItem = new QListViewItem(listServers);
+ newItem->setText(0,*it_servers);
+ newItem->setText(1,*it_ipservers);
+ newItem->setSelected(false);
+ ++it_ipservers;
+ }
+}
+
+/** Write servers lists */
+void KGalleryDialog::configWrite()
+{
+ QStringList servers;
+ QStringList ipservers;
+ KConfig *config = KGlobal::config();
+
+ config->setGroup( "kgallerydialog" );
+ config->writeEntry("Splitter_size", _split->sizes() );
+ config->writeEntry("Geometry", size() );
+ config->sync();
+
+ config->setGroup("Galleries Servers");
+ QListViewItem *item = listServers->firstChild();
+ while (item) {
+ servers.append( item->text(0) );
+ ipservers.append( item->text(1) );
+ item = item->nextSibling();
+ }
+ config->writeEntry("Servers", servers);
+ config->writeEntry("ServersIP", ipservers);
+
+ config->sync();
+}
+
+/** No descriptions */
+void KGalleryDialog::slotButtonAdd()
+{
+ if( (lineName->text()).isEmpty() || (lineAddress->text()).isEmpty() )
+ {
+ KMessageBox::sorry(this, i18n("You need to specify a server!"));
+ return;
+ }
+
+ QListViewItem *newItem = new QListViewItem(listServers);
+ newItem->setText(0,lineName->text());
+ newItem->setText(1,lineAddress->text());
+ newItem->setSelected(false);
+}
+
+/** Open selected document */
+void KGalleryDialog::accept()
+{
+ if (getURL().isEmpty())
+ KMessageBox::sorry(this, i18n("You need to specify the file to open!"));
+ else
+ {
+ configWrite();
+ KGalleryDialogBase::accept();
+ }
+// done( QDialog::Accepted );
+}
+
+/** Select Server */
+void KGalleryDialog::slotServerSelected( QListViewItem *item )
+{
+ if (!item)
+ return;
+
+ KURL url_server = KURL( item->text(1) );
+
+ listDocuments->clear();
+ openFile( url_server );
+}
+
+/** Get keduca test url */
+KURL KGalleryDialog::getURL()
+{
+ QListViewItem *item = listDocuments->currentItem();
+
+ if (!item)
+ return KURL();
+
+ QString urlAddress = item->text(5);
+
+ if( _currentURL.isLocalFile() && !KURL(urlAddress).isValid() )
+ {
+ if( !QFileInfo(urlAddress).exists() )
+ urlAddress = _currentURL.directory(false,true) + urlAddress;
+ kdDebug()<< "Imagen en local" <<endl;
+ } else if( !_currentURL.isLocalFile() && !KURL(urlAddress).isValid() )
+ urlAddress = _currentURL.protocol() + "://" + _currentURL.host() + _currentURL.directory(false,true) + urlAddress;
+
+ kdDebug()<< urlAddress <<endl;
+ return KURL( urlAddress );
+}
+
+/** Add url */
+void KGalleryDialog::putURL(const KURL &urlFile)
+{
+ QListViewItem *newItem = new QListViewItem(listServers);
+ newItem->setText( 1, urlFile.url() );
+ newItem->setSelected(false);
+}
diff --git a/keduca/libkeduca/kgallerydialog.h b/keduca/libkeduca/kgallerydialog.h
new file mode 100644
index 00000000..a662bde6
--- /dev/null
+++ b/keduca/libkeduca/kgallerydialog.h
@@ -0,0 +1,70 @@
+/***************************************************************************
+ kgallerydialog.h - description
+ -------------------
+ begin : mar abr 1 2003
+ copyright : (C) 2003 by javi
+ email : javi@recibos
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef KGALLERYDIALOG_H
+#define KGALLERYDIALOG_H
+
+#include "kgallerydialogbase.h"
+
+#include <kurl.h>
+// #include <kio/global.h>
+// #include <kio/job.h>
+
+/**Gallery
+ *@author Javier Campos
+ */
+
+// forward declarations
+class KTempFile;
+
+namespace KIO { class Job; }
+
+class KGalleryDialog : public KGalleryDialogBase {
+ Q_OBJECT
+public:
+ KGalleryDialog(QWidget *parent=0, const char *name=0);
+ ~KGalleryDialog();
+ /** Open keduca file. This function can open a remote or local url. */
+ bool openFile( const KURL &url );
+ /** Get keduca test url */
+ KURL getURL();
+ /** Add url */
+ void putURL(const KURL &urlFile);
+protected slots: // Private slots
+ /** No descriptions */
+ void slotButtonAdd();
+ /** Open selected document */
+ void accept();
+ /** Select Server */
+ void slotServerSelected( QListViewItem *item );
+protected:
+ /** Open keduca file. This function does the actual work and expects a local filename . */
+ bool loadFile( const QString &filename );
+private: // Private attributes
+ /** Current url */
+ KURL _currentURL;
+ /** The temporary file to which the document is saved, NULL if no temporary file is needed */
+ KTempFile *_tmpfile;
+private: // Private methods
+ /** Read servers */
+ void configRead();
+ /** Write servers lists */
+ void configWrite();
+ /** Init gui settings */
+};
+
+#endif
diff --git a/keduca/libkeduca/kgallerydialogbase.ui b/keduca/libkeduca/kgallerydialogbase.ui
new file mode 100644
index 00000000..ccd51e46
--- /dev/null
+++ b/keduca/libkeduca/kgallerydialogbase.ui
@@ -0,0 +1,370 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>KGalleryDialogBase</class>
+<widget class="QDialog">
+ <property name="name">
+ <cstring>KGalleryDialogBase</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>657</width>
+ <height>400</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>Gallery</string>
+ </property>
+ <property name="focusPolicy">
+ <enum>TabFocus</enum>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout13</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout4</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_2</cstring>
+ </property>
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ <property name="alignment">
+ <set>AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QLineEdit">
+ <property name="name">
+ <cstring>lineName</cstring>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout3</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2</cstring>
+ </property>
+ <property name="text">
+ <string>Address:</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit">
+ <property name="name">
+ <cstring>lineAddress</cstring>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout12</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <spacer>
+ <property name="name">
+ <cstring>spacer4</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Preferred</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>10</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>buttonAdd</cstring>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>&amp;Add Server</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="Line">
+ <property name="name">
+ <cstring>line1</cstring>
+ </property>
+ <property name="frameShape">
+ <enum>HLine</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>Sunken</enum>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ </widget>
+ <widget class="QSplitter">
+ <property name="name">
+ <cstring>_split</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <widget class="QListView">
+ <column>
+ <property name="text">
+ <string>Servers</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Address</string>
+ </property>
+ <property name="clickable">
+ <bool>false</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <property name="name">
+ <cstring>listServers</cstring>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <property name="showSortIndicator">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QListView">
+ <column>
+ <property name="text">
+ <string>Description</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Language</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Category</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Type</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Author</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Address</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <property name="name">
+ <cstring>listDocuments</cstring>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <property name="showSortIndicator">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout2</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>buttonHelp</cstring>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>&amp;Help</string>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer2</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>buttonOpen</cstring>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>&amp;Open</string>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>buttonCancel</cstring>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>&amp;Cancel</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+</widget>
+<connections>
+ <connection>
+ <sender>buttonAdd</sender>
+ <signal>clicked()</signal>
+ <receiver>KGalleryDialogBase</receiver>
+ <slot>slotButtonAdd()</slot>
+ </connection>
+ <connection>
+ <sender>buttonCancel</sender>
+ <signal>clicked()</signal>
+ <receiver>KGalleryDialogBase</receiver>
+ <slot>reject()</slot>
+ </connection>
+ <connection>
+ <sender>buttonOpen</sender>
+ <signal>clicked()</signal>
+ <receiver>KGalleryDialogBase</receiver>
+ <slot>accept()</slot>
+ </connection>
+ <connection>
+ <sender>listServers</sender>
+ <signal>selectionChanged(QListViewItem*)</signal>
+ <receiver>KGalleryDialogBase</receiver>
+ <slot>slotServerSelected(QListViewItem*)</slot>
+ </connection>
+</connections>
+<slots>
+ <slot>slotButtonAdd()</slot>
+ <slot>slotServerSelected(QListViewItem*)</slot>
+</slots>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>