[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-edu-devel
Subject: Re: [kde-edu]: [patch] KVocTrain
From: Anne-Marie Mahfouf <annemarie.mahfouf () free ! fr>
Date: 2004-10-21 12:13:57
Message-ID: 200410210813.58095.annemarie.mahfouf () free ! fr
[Download RAW message or body]
On 20 October 2004 22:10, Peter Hedlund wrote:
> Hi all,
>
> I've attached a patch for KVocTrain. It implements the use of KURL for file
> handling and restructures some of the initialization code.
>
> Since there are many small changes in several files I'd appreciate a review
> before I commit.
>
> Xmlui is next on my todo...
>
> Thanks,
> Peter
Hi,
Tested. I fixed 2 getFileName() that were left, here the new diff foryou to
review and commit.
Thanks a lot for your work, Peter.
Anne-Marie
["kvoctrain.diff" (text/x-diff)]
? .cvsignore
Index: kvoctrain/kva_config.cpp
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/kva_config.cpp,v
retrieving revision 1.33
diff -u -r1.33 kva_config.cpp
--- kvoctrain/kva_config.cpp 4 Sep 2004 11:33:47 -0000 1.33
+++ kvoctrain/kva_config.cpp 21 Oct 2004 12:11:06 -0000
@@ -277,16 +277,16 @@
{
saveOptions(false);
if (doc) {
- config->writeEntry(CFG_FILENAME,doc->getFileName());
+ config->writeEntry(CFG_FILENAME,doc->URL().path());
config->writeEntry(CFG_TITLE,doc->getTitle());
config->writeEntry(CFG_MODIFIED,doc->isModified());
config->writeEntry(CFG_QUERYMODE, querymode);
- QString filename=doc->getFileName();
+ QString filename=doc->URL().path();
QString tempname = kapp->tempSaveName(filename);
saveDocProps(doc);
- doc->saveAs(this, tempname, doc->getTitle(), kvoctrainDoc::automatic, separator, &paste_order);
+ doc->saveAs(this, KURL(tempname), doc->getTitle(), kvoctrainDoc::automatic, separator, &paste_order);
}
}
@@ -305,11 +305,11 @@
pdlg = new ProgressDlg (QString(), QString(),
kapp->makeStdCaption(""));
pdlg->show();
- doc = new kvoctrainDoc (this, tempname, separator, &paste_order);
+ doc = new kvoctrainDoc (this, KURL(tempname), separator, &paste_order);
removeProgressBar();
doc->setModified();
doc->setTitle(title);
- doc->setFileName(filename);
+ doc->setURL(KURL(filename));
setCaption(kapp->makeStdCaption(doc->getTitle(), false, doc->isModified()));
QFile::remove(tempname);
}
@@ -318,7 +318,7 @@
pdlg = new ProgressDlg (QString(), QString(),
kapp->makeStdCaption(""));
pdlg->show();
- doc = new kvoctrainDoc (this, filename, separator, &paste_order);
+ doc = new kvoctrainDoc (this, KURL(filename), separator, &paste_order);
removeProgressBar();
setCaption(kapp->makeStdCaption(doc->getTitle(), false, doc->isModified()));
}
Index: kvoctrain/kva_init.cpp
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/kva_init.cpp,v
retrieving revision 1.41
diff -u -r1.41 kva_init.cpp
--- kvoctrain/kva_init.cpp 14 Jul 2004 14:55:00 -0000 1.41
+++ kvoctrain/kva_init.cpp 21 Oct 2004 12:11:06 -0000
@@ -7,11 +7,11 @@
-----------------------------------------------------------------------
begin : Thu Mar 11 20:50:53 MET 1999
-
+
copyright : (C) 1999-2001 Ewald Arnold
(C) 2001 The KDE-EDU team
-
- email : kvoctrain@ewald-arnold.de
+
+ email : kvoctrain@ewald-arnold.de
-----------------------------------------------------------------------
@@ -80,7 +80,8 @@
initMenuBar();
initToolBar();
initStatusBar();
- initView(name);
+ initDoc();
+ initView();
setIcon (QPixmap (locate("data", "kvoctrain/mini-kvoctrain.xpm" )));
int cc = Prefs::currentCol();
@@ -379,45 +380,33 @@
}
-void kvoctrainApp::initView(const QString &name)
-{
- view = 0;
-
- pdlg = new ProgressDlg (QString(), QString(),
- kapp->makeStdCaption(i18n("Loading Vocabulary File")));
+void kvoctrainApp::initDoc( )
+{
+ pdlg = new ProgressDlg (QString(), QString(), kapp->makeStdCaption(i18n("Loading Vocabulary File")));
pdlg->show();
- kvoctrainExpr::setPixmap(kvoctrainExpr::ExprInQuery,
- QPixmap(locate("data", "kvoctrain/entry-in-query.png")));
- kvoctrainExpr::setPixmap(kvoctrainExpr::ExprInactive,
- QPixmap(locate("data", "kvoctrain/entry-inactive.png")));
-
- if (!name.isEmpty()) {
- doc = new kvoctrainDoc(this, name, separator, &paste_order);
- if (doc) {
- addRecentFile(name);
- }
- }
- else {
- if (recent_files.count() > 0)
- doc = new kvoctrainDoc(this, recent_files[0], separator, &paste_order);
- else
- doc = new kvoctrainDoc(this, "", separator, &paste_order);
- }
+ kvoctrainExpr::setPixmap(kvoctrainExpr::ExprInQuery, QPixmap(locate("data", "kvoctrain/entry-in-query.png")));
+ kvoctrainExpr::setPixmap(kvoctrainExpr::ExprInactive, QPixmap(locate("data", "kvoctrain/entry-inactive.png")));
+
+ if (recent_files.count() > 0)
+ doc = new kvoctrainDoc(this, KURL(recent_files[0]), separator, &paste_order);
+ else
+ doc = new kvoctrainDoc(this, KURL(""), separator, &paste_order);
+
removeProgressBar();
loadDocProps(doc);
if (doc->numLangs() == 0)
doc->appendLang("en");
-
- view = new kvoctrainView(doc, langset, gradecols, this);
connect (doc, SIGNAL (docModified(bool)), this, SLOT(slotModifiedDoc(bool)));
doc->setModified(false);
+}
+
+void kvoctrainApp::initView()
+{
+ view = new kvoctrainView(doc, langset, gradecols, this);
view->setResizer (header_resizer);
view->getTable()->setFont(tablefont);
setCentralWidget(view);
-
- ////////////////////////////////////////////////////////////////////
- // prepare dock window in panel
slotStatusMsg(IDS_DEFAULT);
}
Index: kvoctrain/kva_io.cpp
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/kva_io.cpp,v
retrieving revision 1.40
diff -u -r1.40 kva_io.cpp
--- kvoctrain/kva_io.cpp 13 Jul 2004 22:10:17 -0000 1.40
+++ kvoctrain/kva_io.cpp 21 Oct 2004 12:11:06 -0000
@@ -57,23 +57,6 @@
#define FILTER_WPATTERN i18n(PATTERN_ML)+i18n(PATTERN_VCB)+i18n(PATTERN_CSV)+i18n(PATTERN_LEX)+i18n(PATTERN_ALL)
-// helper that gets a file name (it only differs in the caption of the dialog)
-static QString getFileName(const QString &caption,
- const QString &dir = 0, const QString &filter = 0,
- QWidget* parent = 0, const QString &name = 0)
-{
- QString filename;
- KFileDialog dlg(dir, filter, parent, name.local8Bit(), true /*, false*/);
-
- dlg.setCaption(caption);
-
- if (dlg.exec() == QDialog::Accepted)
- filename = dlg.selectedFile();
-
- return filename;
-}
-
-
void kvoctrainApp::slotTimeOutBackup()
{
if (backupTime > 0 && doc && doc->isModified() ) {
@@ -126,7 +109,7 @@
}
if (save) {
- if (!doc->getFileName().isEmpty())
+ if (!doc->URL().isEmpty())
slotFileSave(); // save and exit
if (doc->isModified())
{
@@ -179,7 +162,7 @@
slotStatusMsg(msg);
prepareProgressBar();
- doc = new kvoctrainDoc (this, name, separator, &paste_order);
+ doc = new kvoctrainDoc (this, KURL(name), separator, &paste_order);
removeProgressBar();
loadDocProps(doc);
addRecentFile(name);
@@ -251,7 +234,7 @@
view->setView (0, langset, gradecols);
delete doc;
QString name = "";
- doc = new kvoctrainDoc (this, name, separator, &paste_order);
+ doc = new kvoctrainDoc (this, KURL(name), separator, &paste_order);
loadDocProps(doc);
if (doc->numLangs() == 0) {
QString l = "en";
@@ -275,9 +258,8 @@
QString s;
if (recent_files.count() > 0)
s = recent_files[0];
- QString name = getFileName(kapp->makeStdCaption(i18n("Open Vocabulary File")),
- s, FILTER_RPATTERN, parentWidget());
- loadfileFromPath(KURL(name));
+ KURL url = KFileDialog::getOpenURL(s, FILTER_RPATTERN, parentWidget(), i18n("Open Vocabulary File"));
+ loadfileFromPath(url, true);
}
slotStatusMsg(IDS_DEFAULT);
}
@@ -295,7 +277,7 @@
slotStatusMsg(msg);
prepareProgressBar();
- doc = new kvoctrainDoc (this, url.path(), separator, &paste_order);
+ doc = new kvoctrainDoc (this, url, separator, &paste_order);
removeProgressBar();
loadDocProps(doc);
view->setView(doc, langset, gradecols);
@@ -315,11 +297,10 @@
if (queryExit() ) {
QString s;
s = locate("data", "kvoctrain/examples/");
- QString name = getFileName(kapp->makeStdCaption(i18n("Open Example Vocabulary File")),
- s, FILTER_RPATTERN, parentWidget());
- loadfileFromPath(KURL(name), false);
+ KURL url = KFileDialog::getOpenURL(s, FILTER_RPATTERN, parentWidget(), i18n("Open Example Vocabulary File"));
+ loadfileFromPath(url, false);
if (doc)
- doc->setFileName(QString::null);
+ doc->URL().setFileName(QString::null);
}
slotStatusMsg(IDS_DEFAULT);
}
@@ -332,16 +313,16 @@
QString s;
if (recent_files.count() > 0)
s = recent_files[0];
- QString name = getFileName(kapp->makeStdCaption(i18n("Merge Vocabulary File")),
- s, FILTER_RPATTERN, parentWidget());
- if (!name.isEmpty() ) {
+ KURL url = KFileDialog::getOpenURL(s, FILTER_RPATTERN, parentWidget(), i18n("Merge Vocabulary File"));
+
+ if (!url.isEmpty() ) {
QString format = i18n("Loading %1");
- QString msg = format.arg(name);
+ QString msg = format.arg(url.path());
slotStatusMsg(msg);
prepareProgressBar();
- kvoctrainDoc *new_doc = new kvoctrainDoc (this, name, separator, &paste_order);
+ kvoctrainDoc *new_doc = new kvoctrainDoc (this, url, separator, &paste_order);
connect (new_doc, SIGNAL (docModified(bool)), this, SLOT(slotModifiedDoc(bool)));
doc->setModified(false);
removeProgressBar();
@@ -362,7 +343,7 @@
vector<QString> new_usages = new_doc->getUsageDescr();
format = i18n("Merging %1");
- msg = format.arg(name);
+ msg = format.arg(url.path());
slotStatusMsg(msg);
QApplication::setOverrideCursor( waitCursor );
@@ -566,7 +547,7 @@
}
}
delete (new_doc);
- addRecentFile (name);
+ addRecentFile (url.path());
}
view->setView(doc, langset, gradecols);
@@ -582,25 +563,24 @@
if (entryDlg != 0)
commitEntryDlg(false);
- if (doc->getFileName().isEmpty() ) {
+ if (doc->URL().isEmpty() ) {
slotFileSaveAs();
return;
}
QString format = i18n("Saving %1");
- QString msg = format.arg(doc->getFileName());
+ QString msg = format.arg(doc->URL().path());
slotStatusMsg(msg);
// remove previous backup
- QFile::remove(QFile::encodeName(doc->getFileName()+"~"));
- ::rename (QFile::encodeName(doc->getFileName()),
- QFile::encodeName(doc->getFileName()+"~"));
+ QFile::remove(QFile::encodeName(doc->URL().path()+"~"));
+ ::rename (QFile::encodeName(doc->URL().path()),
+ QFile::encodeName(doc->URL().path()+"~"));
prepareProgressBar();
saveDocProps(doc);
- doc->saveAs(this, doc->getFileName(), doc->getTitle(),
- kvoctrainDoc::automatic, separator, &paste_order);
- addRecentFile(doc->getFileName());
+ doc->saveAs(this, doc->URL(), doc->getTitle(), kvoctrainDoc::automatic, separator, &paste_order);
+ addRecentFile(doc->URL().path());
removeProgressBar();
slotStatusMsg(IDS_DEFAULT);
@@ -682,40 +662,30 @@
commitEntryDlg(false);
QString s;
-/*
- if (recent_files.count() > 0)
- s = recent_files[0];
-*/
- QString name = getFileName(kapp->makeStdCaption(i18n("Save Vocabulary As")),
- s, FILTER_WPATTERN, parentWidget());
- if (!name.isEmpty() ) {
-
- QFile file (name);
- if (file.exists() ) {
- QString format = i18n("Your selected file exists already.\n"
- "Do you want to overwrite \"%1\"?");
- QString msg = format.arg(name);
+ KURL url = KFileDialog::getSaveURL(s, FILTER_WPATTERN, parentWidget(), i18n("Save Vocabulary As"));
- int exit = KMessageBox::warningYesNo(this,
- msg,
- kapp->makeStdCaption(i18n("File Exists")));
- if(exit!=KMessageBox::Yes)
- return;
+ if (!url.isEmpty() ) {
+ QFileInfo fileinfo(url.path());
+ if (fileinfo.exists() && KMessageBox::questionYesNo(0,
+ i18n("<qt>The file<br><b>%1</b><br>already exists. Do you want to overwrite it?</qt>")
+ .arg(url.path())) == KMessageBox::No)
+ {
+ // do nothing
}
+ else
if (doc) {
QString format = i18n("Saving %1");
- QString msg = format.arg(name);
+ QString msg = format.arg(url.path());
slotStatusMsg(msg);
- QFile::remove(QFile::encodeName(name+"~")); // remove previous backup
- ::rename (QFile::encodeName(name), QFile::encodeName(QString(name+"~")));
+ QFile::remove(QFile::encodeName(url.path()+"~")); // remove previous backup
+ ::rename (QFile::encodeName(url.path()), QFile::encodeName(QString(url.path()+"~")));
saveDocProps(doc);
prepareProgressBar();
- doc->saveAs(this, name, doc->getTitle(),
- kvoctrainDoc::automatic, separator, &paste_order);
- addRecentFile(doc->getFileName());
+ doc->saveAs(this, url, doc->getTitle(), kvoctrainDoc::automatic, separator, &paste_order);
+ addRecentFile(doc->URL().path());
removeProgressBar();
}
}
@@ -744,35 +714,31 @@
seldoc.appendEntry(doc->getEntry(i));
QString s;
- QString name = getFileName(kapp->makeStdCaption(i18n("Save Vocabulary Block As")),
- s, FILTER_WPATTERN, parentWidget());
- if (!name.isEmpty() ) {
-
- QFile file (name);
- if (file.exists() ) {
- QString format = i18n("Your selected file exists already.\n"
- "Do you want to overwrite \"%1\"?");
- QString msg = format.arg(name);
+ KURL url = KFileDialog::getSaveURL(s, FILTER_WPATTERN, parentWidget(), i18n("Save Vocabulary As"));
- int exit = KMessageBox::warningYesNo(this, msg,
- kapp->makeStdCaption(i18n("File Exists")));
- if(exit!=KMessageBox::Yes)
- return;
+ if (!url.isEmpty() ) {
+ QFileInfo fileinfo(url.path());
+ if (fileinfo.exists() && KMessageBox::questionYesNo(0,
+ i18n("<qt>The file<br><b>%1</b><br>already exists. Do you want to overwrite it?</qt>")
+ .arg(url.path())) == KMessageBox::No)
+ {
+ // do nothing
}
+ else
+ {
+ QString format = i18n("Saving %1");
+ QString msg = format.arg(url.path());
+ slotStatusMsg(msg);
- QString format = i18n("Saving %1");
- QString msg = format.arg(name);
- slotStatusMsg(msg);
-
- QFile::remove(name+"~"); // remove previous backup
- // FIXME: check error
- ::rename (QFile::encodeName(name), QFile::encodeName(name+"~"));
- saveDocProps(&seldoc);
+ QFile::remove(url.path()+"~"); // remove previous backup
+ // FIXME: check error
+ ::rename (QFile::encodeName(url.path()), QFile::encodeName(url.path()+"~"));
+ saveDocProps(&seldoc);
- prepareProgressBar();
- seldoc.saveAs(this, name, i18n ("Part of: ") + doc->getTitle(),
- kvoctrainDoc::automatic, separator, &paste_order);
- removeProgressBar();
+ prepareProgressBar();
+ seldoc.saveAs(this, url, i18n ("Part of: ") + doc->getTitle(), kvoctrainDoc::automatic, separator, &paste_order);
+ removeProgressBar();
+ }
}
slotStatusMsg(IDS_DEFAULT);
}
Index: kvoctrain/kvoctrain.h
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/kvoctrain.h,v
retrieving revision 1.32
diff -u -r1.32 kvoctrain.h
--- kvoctrain/kvoctrain.h 11 Jul 2004 22:34:19 -0000 1.32
+++ kvoctrain/kvoctrain.h 21 Oct 2004 12:11:06 -0000
@@ -7,10 +7,10 @@
-----------------------------------------------------------------------
begin : Thu Mar 11 20:50:53 MET 1999
-
+
copyright : (C) 1999-2001 Ewald Arnold
(C) 2001 The KDE-EDU team
-
+
email : kvoctrain@ewald-arnold.de
-----------------------------------------------------------------------
@@ -88,8 +88,10 @@
/** setup the statusbar */
void initStatusBar();
void clearStatusBar();
- /** setup the mainview*/
- void initView(const QString &name);
+ /** setup the main document*/
+ void initDoc();
+ /** setup the main view*/
+ void initView();
/** save the app-specific options on slotAppExit or by an Options dialog */
void saveOptions(bool all);
/** read the app-specific options on init() or by an Options dialog */
@@ -109,13 +111,12 @@
void enableCommand(int id_);
/** disable menuentries/toolbar items */
void disableCommand(int id_);
- /** add a opened file to the recent file list and update recent_file_menu
- */
+ /** add a opened file to the recent file list and update recent_file_menu */
void addRecentFile(const QString &file);
/** Whether the user has selected a range of items. **/
bool hasSelection();
-
+
signals:
void progressChanged (kvoctrainDoc *, int curr_percent);
@@ -358,6 +359,6 @@
bool show_more;
bool i_know;
};
-
+
#endif // KVOCTRAIN_H
Index: kvoctrain/common-dialogs/ProgressDlg.cpp
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/common-dialogs/ProgressDlg.cpp,v
retrieving revision 1.10
diff -u -r1.10 ProgressDlg.cpp
--- kvoctrain/common-dialogs/ProgressDlg.cpp 23 Feb 2004 15:02:54 -0000 1.10
+++ kvoctrain/common-dialogs/ProgressDlg.cpp 21 Oct 2004 12:11:06 -0000
@@ -61,7 +61,7 @@
progress->setProgress(val);
if (doc == 0 && new_doc != 0) {
doc = new_doc;
- QString s = doc->getFileName();
+ QString s = doc->URL().path();
int pos;
bool cut = false;
while ((pos = s.find ('/')) >= 0) {
Index: kvoctrain/kvt-core/kvd_rb_kvtml1.cpp
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/kvt-core/kvd_rb_kvtml1.cpp,v
retrieving revision 1.16
diff -u -r1.16 kvd_rb_kvtml1.cpp
--- kvoctrain/kvt-core/kvd_rb_kvtml1.cpp 19 May 2004 12:22:09 -0000 1.16
+++ kvoctrain/kvt-core/kvd_rb_kvtml1.cpp 21 Oct 2004 12:11:06 -0000
@@ -826,7 +826,7 @@
unknown_attr = true;
- QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(getFileName()).arg(line);
+ QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line);
QString format = i18n(
"Your document contains an unknown attribute <%1> " // keep trailing space
@@ -850,7 +850,7 @@
{
unknown_elem = true;
- QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(getFileName()).arg(line);
+ QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line);
QString format = i18n(
"Your document contains an unknown tag <%1>. " // keep trailing space
@@ -871,7 +871,7 @@
{
QApplication::setOverrideCursor( arrowCursor, true );
QString s = kapp->makeStdCaption(i18n("Error"));
- QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(getFileName()).arg(line);
+ QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line);
QString msg = text;
KMessageBox::error(0, ln+msg, s);
@@ -883,7 +883,7 @@
{
QApplication::setOverrideCursor( arrowCursor, true );
QString s = kapp->makeStdCaption(i18n("Warning"));
- QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(getFileName()).arg(line);
+ QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line);
QString msg = text;
KMessageBox::information(0, ln+msg, s);
QApplication::restoreOverrideCursor();
Index: kvoctrain/kvt-core/kvoctraindoc.cpp
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.cpp,v
retrieving revision 1.29
diff -u -r1.29 kvoctraindoc.cpp
--- kvoctrain/kvt-core/kvoctraindoc.cpp 26 Jun 2004 18:10:37 -0000 1.29
+++ kvoctrain/kvt-core/kvoctraindoc.cpp 21 Oct 2004 12:11:06 -0000
@@ -7,7 +7,7 @@
-----------------------------------------------------------------------
begin : Thu Mar 11 20:50:53 MET 1999
-
+
copyright : (C) 1999-2001 Ewald Arnold
(C) 2001 The KDE-EDU team
email : kvoctrain@ewald-arnold.de
@@ -33,6 +33,7 @@
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>
+#include <kio/netaccess.h>
#include <qfileinfo.h>
@@ -84,35 +85,31 @@
setCurrentLesson (0);
queryorg = "";
querytrans = "";
- mainfile = "";
+ doc_url.setFileName("");
doctitle = "";
author = "";
}
-kvoctrainDoc::kvoctrainDoc(QObject *parent, QString filename,
- QString separator, QStringList *lang_order)
+kvoctrainDoc::kvoctrainDoc(QObject *parent, const KURL& url, QString separator, QStringList *lang_order)
{
Init();
- mainfile = filename;
- connect( this, SIGNAL(progressChanged(kvoctrainDoc*,int)),
- parent, SLOT(slotProgress(kvoctrainDoc*,int)) );
+ doc_url = url;
+ connect( this, SIGNAL(progressChanged(kvoctrainDoc*,int)), parent, SLOT(slotProgress(kvoctrainDoc*,int)) );
- if (!mainfile.isEmpty()) {
- QFile f( filename );
- QFileInfo fi (f);
- bool isfile = fi.isFile() || fi.isSymLink();
- if (!f.exists() || !isfile) {
- QString format = i18n("Could not open \"%1\"\n"
- "Probably this is not a regular file or it does not exist.");
- QString msg = format.arg(mainfile);
- KMessageBox::sorry(0, msg, kapp->makeStdCaption(i18n("I/O Failure")));
- mainfile = "unknown.kvtml";
+ QString tmpfile;
+ if (KIO::NetAccess::download( url, tmpfile, 0 ))
+ {
+ QFile f(tmpfile);
+ if (!f.open(IO_ReadOnly))
+ {
+ KMessageBox::error(0, i18n("<qt>Cannot open file<br><b>%1</b></qt>").arg(url.path()));
+ doc_url.setFileName("unknown.kvtml");
return;
}
- FileType ft = detectFT(filename);
+ FileType ft = detectFT(url.path());
bool read = false;
while (!read) {
@@ -121,56 +118,36 @@
switch (ft) {
case kvtml:
{
- QFile f( filename );
- if (f.open( IO_ReadOnly )) {
- QTextStream is (&f);
- read = loadFromKvtMl (is);
- f.close();
- }
+ QTextStream is (&f);
+ read = loadFromKvtMl (is);
}
break;
case vt_lex:
{
- QFile f( filename );
- if (f.open( IO_ReadOnly )) {
- QTextStream is (&f);
- read = loadFromLex (is);
- f.close();
- }
+ QTextStream is (&f);
+ read = loadFromLex (is);
}
break;
case vt_vcb:
{
- QFile f( filename );
- if (f.open( IO_ReadOnly )) {
- QTextStream is (&f);
- read = loadFromVcb (is);
- f.close();
- }
+ QTextStream is (&f);
+ read = loadFromVcb (is);
}
break;
case csv:
{
- QFile f( filename );
- if (f.open( IO_ReadOnly )) {
- QTextStream is (&f);
- read = loadFromCsv (is, separator, lang_order);
- f.close();
- }
+ QTextStream is (&f);
+ read = loadFromCsv (is, separator, lang_order);
}
break;
default:
{
- QFile f( mainfile );
- if (f.open( IO_ReadOnly )) {
- QTextStream is (&f);
- read = loadFromKvtMl (is);
- f.close();
- }
+ QTextStream is (&f);
+ read = loadFromKvtMl (is);
}
}
@@ -182,7 +159,7 @@
return;
}
QString format = i18n("Could not load \"%1\"\nDo you want to try again?");
- QString msg = format.arg(mainfile);
+ QString msg = format.arg(url.path());
int result = KMessageBox::warningContinueCancel(0, msg,
kapp->makeStdCaption(i18n("I/O Failure")),
i18n("&Retry"));
@@ -192,6 +169,8 @@
}
}
}
+ f.close();
+ KIO::NetAccess::removeTempFile( tmpfile );
}
}
@@ -201,44 +180,44 @@
}
-bool kvoctrainDoc::saveAs (QObject *parent, QString name, QString title,
- FileType ft,
- const QString &separator, QStringList *lang_order)
+bool kvoctrainDoc::saveAs (QObject *parent, const KURL & url, QString title, FileType ft, const QString &separator,
+ QStringList *lang_order)
{
- connect( this, SIGNAL(progressChanged(kvoctrainDoc*,int)),
- parent, SLOT(slotProgress(kvoctrainDoc*,int)) );
+ connect( this, SIGNAL(progressChanged(kvoctrainDoc*,int)), parent, SLOT(slotProgress(kvoctrainDoc*,int)) );
- QString tmp (name);
+ KURL tmp (url);
if (tmp.isEmpty())
- tmp = mainfile;
+ tmp = doc_url;
if (tmp.isEmpty())
- tmp = "unknown.kvtml";
-
- if (ft == automatic) {
+ tmp.setFileName("unknown.kvtml");
- if (tmp.right(strlen("." KVTML_EXT)) == "." KVTML_EXT)
+ if (ft == automatic)
+ {
+ if (tmp.path().right(strlen("." KVTML_EXT)) == "." KVTML_EXT)
ft = kvtml;
- else if (tmp.right(strlen("." VT5_LEX_EXT)) == "." VT5_LEX_EXT)
+ else if (tmp.path().right(strlen("." VT5_LEX_EXT)) == "." VT5_LEX_EXT)
ft = vt_lex;
- else if (tmp.right(strlen("." VCB_EXT)) == "." VCB_EXT)
+ else if (tmp.path().right(strlen("." VCB_EXT)) == "." VCB_EXT)
ft = vt_vcb;
- else if (tmp.right(strlen("." CSV_EXT)) == "." CSV_EXT)
+ else if (tmp.path().right(strlen("." CSV_EXT)) == "." CSV_EXT)
ft = csv;
- else {
- tmp += "." KVTML_EXT;
+ else
+ {
+ tmp.setFileName(tmp.path() + "." KVTML_EXT);
ft = kvtml;
}
}
bool saved = false;
- while (!saved) {
+ while (!saved)
+ {
- QFile f( tmp);
+ QFile f(tmp.path());
- if (!f.open( IO_WriteOnly )) { // open file for writing
- QString msg = i18n("File \"%1\" is not writable, probably you do not have permission to do this.");
- KMessageBox::error(0, msg.arg(tmp), kapp->makeStdCaption(i18n("I/O Failure")));
+ if (!f.open(IO_WriteOnly))
+ {
+ KMessageBox::error(0, i18n("<qt>Cannot write to file<br><b>%1</b></qt>").arg(tmp.path()));
return false;
}
@@ -278,14 +257,14 @@
if (!saved) {
QString format = i18n("Could not save \"%1\"\nDo you want to try again?");
- QString msg = format.arg(tmp);
+ QString msg = format.arg(tmp.path());
int result = KMessageBox::warningContinueCancel(0, msg,
kapp->makeStdCaption(i18n("I/O Failure")),
i18n("&Retry"));
if ( result == KMessageBox::Cancel ) return false;
}
}
- mainfile = tmp;
+ doc_url = tmp;
dirty = false;
emit docModified(false);
return true;
Index: kvoctrain/kvt-core/kvoctraindoc.h
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.h,v
retrieving revision 1.10
diff -u -r1.10 kvoctraindoc.h
--- kvoctrain/kvt-core/kvoctraindoc.h 17 Jul 2003 12:48:21 -0000 1.10
+++ kvoctrain/kvt-core/kvoctraindoc.h 21 Oct 2004 12:11:06 -0000
@@ -7,11 +7,11 @@
-----------------------------------------------------------------------
begin : Thu Mar 11 20:50:53 MET 1999
-
+
copyright : (C) 1999-2001 Ewald Arnold
(C) 2001 The KDE-EDU team
-
- email : kvoctrain@ewald-arnold.de
+
+ email : kvoctrain@ewald-arnold.de
-----------------------------------------------------------------------
@@ -35,6 +35,8 @@
#include <qobject.h>
+#include <kurl.h>
+
#include "kvoctrainexpr.h"
#include "kvt-xml/XmlReader.h"
@@ -265,8 +267,7 @@
* @param obj calling object
* @param filename name of file to parse
*/
- kvoctrainDoc(QObject* obj, QString name,
- QString separator, QStringList *lang_order = 0);
+ kvoctrainDoc(QObject* obj, const KURL& url, QString separator, QStringList *lang_order = 0);
/** Destructor for the fileclass of the application */
~kvoctrainDoc();
@@ -422,12 +423,11 @@
/** saves the data under the given name
*
- * @param name if name is empty (or NULL) actual name is preserved
+ * @param url if url is empty (or NULL) actual name is preserved
* @result true if successful
*/
- bool saveAs (QObject *parent, QString name, QString title,
- FileType ft,
- const QString &separator, QStringList *lang_order = 0);
+ bool saveAs (QObject *parent, const KURL & url, QString title, FileType ft, const QString &separator,
+ QStringList *lang_order = 0);
/** returns count of entries
*/
@@ -470,11 +470,11 @@
int search(QString substr, int id,
int first=0, int last=-1, bool word_start = false, bool tolerant=false);
- /** returns name of xml file */
- inline QString getFileName() const { return mainfile; }
+ /** returns url of xml file */
+ inline KURL URL() const {return doc_url; }
- /** sets name of xml file */
- inline void setFileName(const QString &s) { mainfile = s; }
+ /** sets url of xml file */
+ inline void setURL(const KURL& url) {doc_url = url;}
/** returns title of xml file */
QString getTitle() const;
@@ -712,7 +712,7 @@
private:
bool dirty;
- QString mainfile;
+ KURL doc_url;
vector<bool> sort_lang;
bool sort_lesson;
bool unknown_attr;
Index: kvoctrain/statistik-dialogs/GenStatPage.cpp
===================================================================
RCS file: /home/kde/kdeedu/kvoctrain/kvoctrain/statistik-dialogs/GenStatPage.cpp,v
retrieving revision 1.7
diff -u -r1.7 GenStatPage.cpp
--- kvoctrain/statistik-dialogs/GenStatPage.cpp 24 Feb 2004 14:46:19 -0000 1.7
+++ kvoctrain/statistik-dialogs/GenStatPage.cpp 21 Oct 2004 12:11:06 -0000
@@ -42,7 +42,7 @@
:
GenStatPageForm( parent, name )
{
- l_filename->setText(doc->getFileName());
+ l_filename->setText(doc->URL().path());
l_title->setText(doc->getTitle());
l_author->setText(doc->getAuthor());
QString s;
_______________________________________________
kde-edu mailing list
kde-edu@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-edu
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic