/* * * ..> wallpaper.exe file style * Returns: * 0 - success * -1 - invalid parameters * -2 - doesn\'t support JPG file * -3 - doesn\'t support Fit or Fill style * -4 - set wallpaper failed */ int main(int argc, const char*argv[]){ if (argc != 3) { std::cout << "Usage:\n\twallpaper file <Tile, Center, Stretch, Fit, Fill>" << std::endl; return -1; } const char* file = argv[1]; const char* stylestr = argv[2]; // Get file path // Convert const char* to WCHAR* int dwLen = strlen(file) + 1; int nwLen = MultiByteToWideChar(CP_ACP, 0, file, dwLen, NULL, 0); PWSTR pszFile = new WCHAR[dwLen]; MultiByteToWideChar(CP_ACP, 0, file, dwLen, pszFile, nwLen); // Check JPG support std::string ext = std::strrchr(file, '.'); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); if (ext == ".jpg"){ if (!SupportJpgAsWallpaper()) { return -2; } } // Get WallpaperStyle WallpaperStyle style = GetWallpaperStyle(stylestr); // Check Fit Fill styles support if (style == Fit || style == Fill){ if (!SupportFitFillWallpaperStyles()){ return -3; } } // Set Wallpaper HRESULT hr = SetDesktopWallpaper(pszFile, style); delete[] pszFile; pszFile = NULL; if (SUCCEEDED(hr)) { return 0; } return -4; }
void HttpWindow::httpFinished() { if (httpRequestAborted) { if (file) { file->close(); file->remove(); delete file; file = 0; } reply->deleteLater(); #ifndef Q_WS_MAEMO_5 progressDialog->hide(); #endif return; } qDebug("Download Finish....."); #ifndef Q_WS_MAEMO_5 progressDialog->hide(); #endif file->flush(); file->close(); QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (reply->error()) { file->remove(); QMessageBox::information(this, tr("HTTP"), tr("Download failed: %1.") .arg(reply->errorString())); downloadButton->setEnabled(true); } else if (!redirectionTarget.isNull()) { QUrl newUrl = url.resolved(redirectionTarget.toUrl()); if (QMessageBox::question(this, tr("HTTP"), tr("Redirect to %1 ?").arg(newUrl.toString()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { url = newUrl; reply->deleteLater(); file->open(QIODevice::WriteOnly); file->resize(0); startRequest(url); return; } } else { // QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); // statusLabel->setText(tr("Downloaded %1 to %2.").arg(fileName).arg(QDir::currentPath())); } reply->deleteLater(); reply = 0; delete file; file = 0; if(FALSE == QFile::exists(bing_filename)) { QString jpgUrl = ""; if(TRUE == QFile::exists(index_filename)) { RetriveJpgUrlFromFile(index_filename, jpgUrl); if(FALSE == jpgUrl.isEmpty()) { file = new QFile(bing_filename); file->open(QIODevice::WriteOnly); startRequest(jpgUrl); } } } else { SetDesktopWallpaper(bing_filename); downloadButton->setEnabled(true); statusLabel->setText("Don't Like this pic?"); QFile::remove(index_filename); QFile::remove(bing_filename); downloadButton->setText("Change Again"); if(MAX_URL_NUMBER == Url_index ) { statusLabel->setText(no_pic_hint); } } }