Example #1
0
	bool saveScreenshots(KviThemeInfo & options, const QString & szOriginalScreenshotPath)
	{
		QImage pix(szOriginalScreenshotPath);
		if(pix.isNull())
		{
			options.setLastError(__tr2qs("Failed to load the specified screenshot image"));
			return false;
		}

		QImage out;

		QString szScreenshotPath = options.directory();

		if(szScreenshotPath.isEmpty())
		{
			options.setLastError(__tr2qs("Invalid option"));
			return false;
		}

		if(!pix.save(szScreenshotPath + KVI_THEME_LARGE_SCREENSHOT_NAME, "PNG"))
		{
			options.setLastError(__tr2qs("Failed to save the screenshot image"));
			return false;
		}

		if(pix.width() > 600 || pix.height() > 450)
			out = pix.scaled(640, 450, QIMAGE_SCALE_MIN, Qt::SmoothTransformation);
		else
			out = pix;

		if(!out.save(szScreenshotPath + KVI_THEME_MEDIUM_SCREENSHOT_NAME, "PNG"))
		{
			options.setLastError(__tr2qs("Failed to save the screenshot image"));
			return false;
		}

		if(pix.width() > 300 || pix.height() > 225)
			out = pix.scaled(300, 225, QIMAGE_SCALE_MIN, Qt::SmoothTransformation);
		else
			out = pix;

		if(!out.save(szScreenshotPath + KVI_THEME_SMALL_SCREENSHOT_NAME, "PNG"))
		{
			options.setLastError(__tr2qs("Failed to save the screenshot image"));
			return false;
		}

		return true;
	}
Example #2
0
	bool packageThemes(
			const QString &szPackagePath,
			const QString &szPackageName,
			const QString &szPackageVersion,
			const QString &szPackageDescription,
			const QString &szPackageAuthor,
			const QString &szPackageImagePath,
			KviPointerList<KviThemeInfo> &lThemeInfoList,
			QString &szError
		)
	{
		if(szPackagePath.isEmpty())
		{
			szError = __tr2qs_ctx("Invalid empty package path","theme");
			return false;
		}

		if(szPackageName.isEmpty())
		{
			szError = __tr2qs_ctx("Invalid empty package name","theme");
			return false;
		}

		QPixmap out;

		if(!szPackageImagePath.isEmpty())
		{
			QImage pix(szPackageImagePath);
			if(pix.isNull())
			{
				szError = __tr2qs_ctx("Failed to load the selected image: please fix it","theme");
				return false;
			}

			if((pix.width() > 300) || (pix.height() > 225))
				out = out.fromImage(pix.scaled(300,225,Qt::KeepAspectRatio));
			else
				out=out.fromImage(pix);
		}

		KviPackageWriter f;

		f.addInfoField("PackageType","ThemePack");
		f.addInfoField("ThemePackVersion",KVI_CURRENT_THEME_ENGINE_VERSION);
		f.addInfoField("Name",szPackageName);
		f.addInfoField("Version",szPackageVersion.isEmpty() ? "1.0.0" : szPackageVersion);
		f.addInfoField("Author",szPackageAuthor);
		f.addInfoField("Description",szPackageDescription);
		// 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
		f.addInfoField("Date",QDateTime::currentDateTime().toString(Qt::ISODate));
		f.addInfoField("Application","KVIrc " KVI_VERSION "." KVI_SOURCES_DATE);

		if(!out.isNull())
		{
			QByteArray * pba = new QByteArray();
			QBuffer buffer(pba,0);
			buffer.open(QIODevice::WriteOnly);
			out.save(&buffer,"PNG");
			buffer.close();
			f.addInfoField("Image",pba); // cool :) [no disk access needed]
		}

		QString szTmp;

		szTmp.setNum(lThemeInfoList.count());
		f.addInfoField("ThemeCount",szTmp);

		int iIdx = 0;
		for(KviThemeInfo * pInfo = lThemeInfoList.first();pInfo;pInfo = lThemeInfoList.next())
		{
			if(pInfo->name().isEmpty())
			{
				szError = __tr2qs_ctx("Invalid theme name","theme");
				return false;
			}
			if(pInfo->version().isEmpty())
			{
				szError = __tr2qs_ctx("Invalid theme version","theme");
				return false;
			}

			QString szSubdir = pInfo->name() + QString("-") + pInfo->version();
			szSubdir.replace(QRegExp("[^a-zA-Z0-9_\\-.][^a-zA-Z0-9_\\-.]*"),"_");

			szTmp = QString("Theme%1Name").arg(iIdx);
			f.addInfoField(szTmp,pInfo->name());
			szTmp = QString("Theme%1Version").arg(iIdx);
			f.addInfoField(szTmp,pInfo->version());
			szTmp = QString("Theme%1Description").arg(iIdx);
			f.addInfoField(szTmp,pInfo->description());
			szTmp = QString("Theme%1Date").arg(iIdx);
			f.addInfoField(szTmp,pInfo->date());
			szTmp = QString("Theme%1Subdirectory").arg(iIdx);
			f.addInfoField(szTmp,szSubdir);
			szTmp = QString("Theme%1Author").arg(iIdx);
			f.addInfoField(szTmp,pInfo->author());
			szTmp = QString("Theme%1Application").arg(iIdx);
			f.addInfoField(szTmp,pInfo->application());
			szTmp = QString("Theme%1ThemeEngineVersion").arg(iIdx);
			f.addInfoField(szTmp,pInfo->themeEngineVersion());
			QPixmap pixScreenshot = pInfo->smallScreenshot();
			if(!pixScreenshot.isNull())
			{
				szTmp = QString("Theme%1Screenshot").arg(iIdx);
				QByteArray * pba = new QByteArray();

				QBuffer bufferz(pba,0);
				bufferz.open(QIODevice::WriteOnly);
				pixScreenshot.save(&bufferz,"PNG");
				bufferz.close();
				f.addInfoField(szTmp,pba);
			}

			if(!f.addDirectory(pInfo->directory(),szSubdir))
			{
				szError = __tr2qs_ctx("Packaging failed","theme");
				szError += ": ";
				szError += f.lastError();
				return false;
			}

			iIdx++;
		}

		if(!f.pack(szPackagePath))
		{
			szError = __tr2qs_ctx("Packaging failed","theme");
			szError += ": ";
			szError += f.lastError();
			return false;
		}

		return true;
	}
Example #3
0
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());

	// 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
	sto.setDate(QLocale().toString(QDateTime::currentDateTime(), "ddd MMM d hh:mm:ss yyyy"));
	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("[^a-zA-Z0-9_\\-.][^a-zA-Z0-9_\\-.]*"),"_");
	sto.setDirectoryAndLocation(szSubdir,KviThemeInfo::User);

	QString szAbsDir = sto.directory();
	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;
}