bool SaveThemeDialog::saveTheme() { m_pImageSelector->commit(); KviThemeInfo sto; sto.setName(m_pThemeNameEdit->text()); if(sto.name().isEmpty()) { QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("You must choose a theme name!","theme"),QMessageBox::Ok, QMessageBox::NoButton,QMessageBox::NoButton); return false; } sto.setAuthor(m_pAuthorNameEdit->text()); sto.setDescription(m_pThemeDescriptionEdit->toPlainText()); QString szTmp; QDateTime date = QDateTime::currentDateTime(); switch(KVI_OPTION_UINT(KviOption_uintOutputDatetimeFormat)) { case 0: // this is the equivalent to an empty date.toString() call, but it's needed // to ensure qt4 will use the default() locale and not the system() one szTmp = QLocale().toString(date, "ddd MMM d hh:mm:ss yyyy"); break; case 1: szTmp = date.toString(Qt::ISODate); break; case 2: szTmp = date.toString(Qt::SystemLocaleShortDate); break; } sto.setDate(szTmp); sto.setVersion(m_pThemeVersionEdit->text()); sto.setApplication("KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); if(sto.version().isEmpty())sto.setVersion("1.0.0"); QString szSubdir = sto.name() + QString("-") + sto.version(); szSubdir.replace(QRegExp("[ \\\\/:][ \\\\/:]*"),"_"); sto.setSubdirectory(szSubdir); QString szAbsDir; g_pApp->getLocalKvircDirectory(szAbsDir,KviApplication::Themes,sto.subdirectory(),true); if(!KviFileUtils::makeDir(szAbsDir)) { QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme directory.","theme"), QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); return false; } if(!KviTheme::save(sto)) { QString szErr = sto.lastError(); QString szMsg2 = QString(__tr2qs_ctx("Unable to save theme: %1","theme")).arg(szErr); QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),szMsg2, QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); return false; } // write down the screenshot, if needed if(!m_szScreenshotPath.isEmpty()) { if(!KviTheme::saveScreenshots(sto,m_szScreenshotPath)) { QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected screenshot image: please fix it","theme"), QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); setCurrentPage(m_pImageSelectionPage); return false; } } QString szMsg = __tr2qs_ctx("Theme saved successfully to %1","theme").arg(szAbsDir); QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg,QMessageBox::Ok, QMessageBox::NoButton,QMessageBox::NoButton); return true; }
void PackThemeDataWidget::parseThemes(KviPointerList<KviThemeInfo> * pThemeInfoList) { QString szPackageName; QString szPackageAuthor; QString szPackageDescription; QString szPackageVersion; KviThemeInfo * pThemeInfo = 0; bool bPackagePathSet = false; QString szPackagePath = QDir::homePath(); KviQString::ensureLastCharIs(szPackagePath,QChar(KVI_PATH_SEPARATOR_CHAR)); if(pThemeInfoList->count() > 1) { szPackageName = "MyThemes"; szPackageAuthor = __tr2qs_ctx("Your name here","theme"); szPackageVersion = "1.0.0"; szPackageDescription = __tr2qs_ctx("Put a package description here...","theme"); } else { if(pThemeInfoList->count() > 0) { pThemeInfo = pThemeInfoList->first(); szPackageName = pThemeInfo->subdirectory(); szPackageAuthor = pThemeInfo->author(); szPackageDescription = pThemeInfo->description(); szPackageVersion = pThemeInfo->version(); szPackagePath += pThemeInfo->subdirectory(); if(szPackagePath.indexOf(QRegExp("[0-9]\\.[0-9]")) == -1) { szPackagePath += "-"; szPackagePath += szPackageVersion; } szPackagePath += KVI_FILEEXTENSION_THEMEPACKAGE; bPackagePathSet = true; } } if(!bPackagePathSet) { szPackagePath += szPackageName; szPackagePath += "-"; szPackagePath += szPackageVersion; szPackagePath += KVI_FILEEXTENSION_THEMEPACKAGE; } QVBoxLayout * pLayout = new QVBoxLayout(this); QString szThemesDescription = "<html><body bgcolor=\"#ffffff\">"; int iIdx = 0; QPixmap pixScreenshot; QString szScreenshotPath; for(pThemeInfo = pThemeInfoList->first(); pThemeInfo; pThemeInfo = pThemeInfoList->next()) { QString szThemeDescription; if(pixScreenshot.isNull()) { pixScreenshot = pThemeInfo->smallScreenshot(); if(!pixScreenshot.isNull()) szScreenshotPath = pThemeInfo->smallScreenshotPath(); } ThemeFunctions::getThemeHtmlDescription( szThemeDescription, pThemeInfo->name(), pThemeInfo->version(), pThemeInfo->description(), pThemeInfo->subdirectory(), pThemeInfo->application(), pThemeInfo->author(), pThemeInfo->date(), pThemeInfo->themeEngineVersion(), pThemeInfo->smallScreenshot(), iIdx ); if(iIdx > 0) szThemesDescription += "<hr>"; szThemesDescription += szThemeDescription; iIdx++; } szThemesDescription += "</body></html>"; QTextEdit * pTextEdit = new QTextEdit(this); pTextEdit->setBackgroundRole(QPalette::Window); pTextEdit->setReadOnly(true); QTextDocument * pDoc = new QTextDocument(pTextEdit); pDoc->setHtml(szThemesDescription); pTextEdit->setDocument(pDoc); pLayout->addWidget(pTextEdit); setField("packageName",QVariant(szPackageName)); setField("packageVersion",szPackageVersion); setField("packageDescription",szPackageDescription); setField("packageAuthor",szPackageAuthor); }