[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/~pino/kweather-plasma/kweather
From: Pino Toscano <pino () kde ! org>
Date: 2008-07-02 15:25:33
Message-ID: 1215012333.186092.2759.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 827303 by pino:
do not keep a temporary file open, but just open the destination file when the job has finished
M +15 -19 weatherlib.cpp
--- branches/work/~pino/kweather-plasma/kweather/weatherlib.cpp #827302:827303
@@ -42,21 +42,20 @@
{
public:
Data();
- ~Data(){ if ( target ) delete target; }
+ ~Data(){}
void clear();
/** The current weather state outside */
struct WeatherInfo wi;
QDateTime age;
- KTemporaryFile *target;
bool downloading;
bool updated;
KIO::Job *job;
};
WeatherLib::Data::Data()
- : target( 0 ), job( 0 )
+ : job( 0 )
{
clear();
}
@@ -67,9 +66,6 @@
downloading = false;
updated = false;
job = 0;
-
- delete target;
- target = 0;
}
WeatherLib::WeatherLib(StationDatabase *stationDB, QObject *parent, const char *name)
@@ -112,14 +108,15 @@
d->downloading = false;
if( !job->error() )
{
- kDebug( 12006) << "Reading: " << d->target->fileName();
- QTextStream *t = new QTextStream( d->target );
- if( t )
+ QFile f(qobject_cast<KIO::FileCopyJob*>(job)->destUrl().toLocalFile());
+ kDebug( 12006) << "Reading:" << f.fileName();
+ if(f.open(QIODevice::ReadOnly))
{
+ QTextStream t(&f);
QString s = QString();
- while ( !t->atEnd() )
+ while ( !t.atEnd() )
{
- s += ' ' + t->readLine();
+ s += ' ' + t.readLine();
}
if ( !s.isEmpty() )
@@ -136,7 +133,7 @@
// File error
kDebug( 12006 ) << "File empty error...";
KPassivePopup::message( i18n("KWeather Error"),
- i18n("The temp file %1 was empty.", d->target->fileName()), (QWidget*)NULL);
+ i18n("The temp file %1 was empty.", f.fileName()), (QWidget*)NULL);
d->updated = false;
}
}
@@ -145,11 +142,9 @@
// File error
kDebug( 12006 ) << "File read error...";
KPassivePopup::message( i18n("KWeather Error"),
- i18n("Could not read the temp file %1.", d->target->fileName()), (QWidget*)NULL);
+ i18n("Could not read the temp file %1.", f.fileName()), (QWidget*)NULL);
d->updated = false;
}
- delete d->target;
- d->target = 0L;
d->job = 0L;
}
@@ -189,13 +184,14 @@
u += d->wi.reportLocation.toUpper().trimmed();
u += ".TXT";
- d->target = new KTemporaryFile();
- d->target->setSuffix("-weather");
- d->target->open();
+ KTemporaryFile target;
+ target.setSuffix("-weather");
+ target.open();
KUrl url(u);
KUrl local;
- local.setPath(d->target->fileName());
+ local.setPath(target.fileName());
+ target.close();
d->job = KIO::file_copy( url, local, -1, KIO::Overwrite | KIO::HideProgressInfo);
d->job->addMetaData("cache", "reload"); // Make sure to get fresh info
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic