Changeset View
Changeset View
Standalone View
Standalone View
app/dictionaryupdatemanager.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 79 | { | |||
---|---|---|---|---|---|
80 | // Make sure to reset this variable to 0. | 80 | // Make sure to reset this variable to 0. | ||
81 | _counter = 0; | 81 | _counter = 0; | ||
82 | emit updateFinished(); | 82 | emit updateFinished(); | ||
83 | } | 83 | } | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | void DictionaryUpdateManager::checkInfoFile( KJob *job ) | 86 | void DictionaryUpdateManager::checkInfoFile( KJob *job ) | ||
87 | { | 87 | { | ||
88 | KIO::StoredTransferJob *storedJob = static_cast<KIO::StoredTransferJob*>( job ); | 88 | KIO::StoredTransferJob *storedJob = qobject_cast<KIO::StoredTransferJob*>( job ); | ||
89 | QByteArray data( storedJob->data() ); | 89 | QByteArray data( storedJob->data() ); | ||
90 | // Check if we have valid data to work with. | 90 | // Check if we have valid data to work with. | ||
91 | if( data.isNull() || data.isEmpty() ) | 91 | if( data.isNull() || data.isEmpty() ) | ||
92 | { | 92 | { | ||
93 | KMessageBox::sorry( 0, i18n( "Update canceled.\nCould not read file." ) ); | 93 | KMessageBox::sorry( nullptr, i18n( "Update canceled.\nCould not read file." ) ); | ||
94 | job->deleteLater(); | 94 | job->deleteLater(); | ||
95 | return; | 95 | return; | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | // We don't need to store this information file in our Hard Disk Drive, | 98 | // We don't need to store this information file in our Hard Disk Drive, | ||
99 | // a temporary file is enough. | 99 | // a temporary file is enough. | ||
100 | QTemporaryFile tempFile; | 100 | QTemporaryFile tempFile; | ||
101 | if( ! tempFile.open() ) | 101 | if( ! tempFile.open() ) | ||
102 | { | 102 | { | ||
103 | KMessageBox::sorry( 0, i18n( "Update canceled.\nCould not open file." ) ); | 103 | KMessageBox::sorry( nullptr, i18n( "Update canceled.\nCould not open file." ) ); | ||
104 | qDebug() << "Could not open tempFile." << endl; | 104 | qDebug() << "Could not open tempFile." << endl; | ||
105 | tempFile.deleteLater(); | 105 | tempFile.deleteLater(); | ||
106 | job->deleteLater(); | 106 | job->deleteLater(); | ||
107 | return; | 107 | return; | ||
108 | } | 108 | } | ||
109 | tempFile.write( data ); | 109 | tempFile.write( data ); | ||
110 | tempFile.close(); | 110 | tempFile.close(); | ||
111 | 111 | | |||
112 | // Get the latest creation date for the EDICT dictionary on the server. | 112 | // Get the latest creation date for the EDICT dictionary on the server. | ||
113 | QDate webFileDate = getFileDate( tempFile ); | 113 | QDate webFileDate = getFileDate( tempFile ); | ||
114 | if( ! webFileDate.isValid() ) | 114 | if( ! webFileDate.isValid() ) | ||
115 | { | 115 | { | ||
116 | // The program should not get to this point. | 116 | // The program should not get to this point. | ||
117 | // Maybe the format/content of (one or both) the files changed? | 117 | // Maybe the format/content of (one or both) the files changed? | ||
118 | // or maybe one or both of the files could not be opened in the | 118 | // or maybe one or both of the files could not be opened in the | ||
119 | // getFileDate function that would return an invalid empty date. | 119 | // getFileDate function that would return an invalid empty date. | ||
120 | KMessageBox::sorry( 0, i18n( "Update canceled.\nThe update information file has an invalid date." ) ); | 120 | KMessageBox::sorry( nullptr, i18n( "Update canceled.\nThe update information file has an invalid date." ) ); | ||
121 | tempFile.deleteLater(); | 121 | tempFile.deleteLater(); | ||
122 | job->deleteLater(); | 122 | job->deleteLater(); | ||
123 | return; | 123 | return; | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | // At this point we have a valid creation date from the server. | 126 | // At this point we have a valid creation date from the server. | ||
127 | // Now we can check our dictionaries. | 127 | // Now we can check our dictionaries. | ||
128 | 128 | | |||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | |||||
234 | } | 234 | } | ||
235 | 235 | | |||
236 | void DictionaryUpdateManager::installDictionary( KJob *job ) | 236 | void DictionaryUpdateManager::installDictionary( KJob *job ) | ||
237 | { | 237 | { | ||
238 | // Increase the number of dictionaries we try to install. | 238 | // Increase the number of dictionaries we try to install. | ||
239 | // This way we can know when we finished with our installed dictionaries. | 239 | // This way we can know when we finished with our installed dictionaries. | ||
240 | _counter++; | 240 | _counter++; | ||
241 | 241 | | |||
242 | KIO::StoredTransferJob *storedJob = static_cast<KIO::StoredTransferJob*>( job ); | 242 | KIO::StoredTransferJob *storedJob = qobject_cast<KIO::StoredTransferJob*>( job ); | ||
243 | QByteArray data( storedJob->data() ); | 243 | QByteArray data( storedJob->data() ); | ||
244 | QString url( storedJob->url().toDisplayString() ); | 244 | QString url( storedJob->url().toDisplayString() ); | ||
245 | 245 | | |||
246 | // What we actually downloaded was a GZIP file that we need to extract. | 246 | // What we actually downloaded was a GZIP file that we need to extract. | ||
247 | // As there is no need to keep this file, we make it a temporary file. | 247 | // As there is no need to keep this file, we make it a temporary file. | ||
248 | QTemporaryFile compressedFile; | 248 | QTemporaryFile compressedFile; | ||
249 | if( ! compressedFile.open() ) | 249 | if( ! compressedFile.open() ) | ||
250 | { | 250 | { | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | |||||
312 | void DictionaryUpdateManager::showUpdateResults() | 312 | void DictionaryUpdateManager::showUpdateResults() | ||
313 | { | 313 | { | ||
314 | // Avoid multiple calls to this slot. | 314 | // Avoid multiple calls to this slot. | ||
315 | disconnect( this, SIGNAL(updateFinished()), | 315 | disconnect( this, SIGNAL(updateFinished()), | ||
316 | this, SLOT(showUpdateResults()) ); | 316 | this, SLOT(showUpdateResults()) ); | ||
317 | 317 | | |||
318 | if( ! _succeeded.isEmpty() && _failed.isEmpty() ) | 318 | if( ! _succeeded.isEmpty() && _failed.isEmpty() ) | ||
319 | { | 319 | { | ||
320 | KMessageBox::information( 0, i18n( "You already have the latest updates." ) ); | 320 | KMessageBox::information( nullptr, i18n( "You already have the latest updates." ) ); | ||
321 | } | 321 | } | ||
322 | else if( _succeeded.isEmpty() && _failed.isEmpty() ) | 322 | else if( _succeeded.isEmpty() && _failed.isEmpty() ) | ||
323 | { | 323 | { | ||
324 | KMessageBox::information( 0, i18n( "Successfully updated your dictionaries." ) ); | 324 | KMessageBox::information( nullptr, i18n( "Successfully updated your dictionaries." ) ); | ||
325 | } | 325 | } | ||
326 | else if( ! _succeeded.isEmpty() && ! _failed.isEmpty() ) | 326 | else if( ! _succeeded.isEmpty() && ! _failed.isEmpty() ) | ||
327 | { | 327 | { | ||
328 | KMessageBox::information( 0, i18n( "Successfully updated:\n%1\n\nFailed to update:\n%2" | 328 | KMessageBox::information( nullptr, i18n( "Successfully updated:\n%1\n\nFailed to update:\n%2" | ||
329 | , _succeeded.join( "\n" ) | 329 | , _succeeded.join( "\n" ) | ||
330 | , _failed.join( "\n" ) ) ); | 330 | , _failed.join( "\n" ) ) ); | ||
331 | } | 331 | } | ||
332 | else if( _succeeded.isEmpty() && ! _failed.isEmpty() ) | 332 | else if( _succeeded.isEmpty() && ! _failed.isEmpty() ) | ||
333 | { | 333 | { | ||
334 | KMessageBox::sorry( 0, i18n( "Failed to update:\n%1" | 334 | KMessageBox::sorry( nullptr, i18n( "Failed to update:\n%1" | ||
335 | , _failed.join( "\n" ) ) ); | 335 | , _failed.join( "\n" ) ) ); | ||
336 | } | 336 | } | ||
337 | 337 | | |||
338 | // Avoid repetitions in our lists. | 338 | // Avoid repetitions in our lists. | ||
339 | _succeeded.clear(); | 339 | _succeeded.clear(); | ||
340 | _failed.clear(); | 340 | _failed.clear(); | ||
341 | } | 341 | } | ||
342 | 342 | | |||
343 | 343 | |