Esempio n. 1
0
bool saveResourceAs(const QString &pResource, const QString &pFilename)
{
    if (QResource(pResource).isValid()) {
        // The resource exists, so write a file with name pFilename and which
        // contents is that of the resource which is retrieved as a QByteArray

        QFile file(pFilename);

        if (file.open(QIODevice::ReadWrite)) {
            QByteArray resource = resourceAsByteArray(pResource);
            bool res;

            res = file.write(resource) == resource.size();

            file.close();

            // Remove the newly created file in case not all the resource was
            // written to it

            if (!res)
                file.remove();

            return res;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Esempio n. 2
0
void MainWindow::initWinSparkle()
{
    // Setup updates feed. This must be done before win_sparkle_init(), but
    // could be also, often more conveniently, done using a VERSIONINFO Windows
    // resource. See the "psdk" example and its .rc file for an example of that
    // (these calls wouldn't be needed then).
    win_sparkle_set_appcast_url("https://winsparkle.org/example/appcast.xml");
    win_sparkle_set_app_details(L"winsparkle.org", L"WinSparkle Qt Example", L"1.0");

    // Set DSA public key used to verify update's signature.
    // This is na example how to provide it from external source (i.e. from Qt
    // resource). See the "psdk" example and its .rc file for an example how to
    // provide the key using Windows resource.
    win_sparkle_set_dsa_pub_pem(reinterpret_cast<const char *>(QResource(":/pem/dsa_pub.pem").data()));

    // Initialize the updater and possibly show some UI
    win_sparkle_init();
}
Esempio n. 3
0
statswinimpl::statswinimpl(Hero *h) 
: QWidget(0,0)
{
	setupUi(this);
	hero = h;
	hwin = new herowinimpl(hero);
	diary = new diarywinimpl();
	
	stayontopToggle(false);
	connect(hero, SIGNAL(done(QString)), this, SLOT(loginDone(QString)));
	
	//трей

#ifdef Q_WS_WIN
        QResource res = QResource("bin/icon.bmp");
#else
        QResource res = QResource("src/icon_128.png");
#endif
	QPixmap pix;
        pix.loadFromData(res.data(), res.size());
	QIcon ico = QIcon(pix);
	tray = new QSystemTrayIcon(ico);
	tray->setVisible(true);
	connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
	
	//меню
	QMenu *menu = new QMenu();
	QAction *hideshow = menu->addAction(tr("Скрыть/Показать"));
	connect(hideshow, SIGNAL(triggered()), this, SLOT(hideshow()));
	menu->addSeparator();
	showmess = menu->addAction(tr("Показывать сообщения"));
	showmess->setCheckable(true);
	showmess->setChecked(true);
	QAction *stayontop = menu->addAction(tr("Поверх всех окон"));
	stayontop->setCheckable(true);
	stayontop->setChecked(false);
	connect(stayontop, SIGNAL(toggled(bool)), this, SLOT(stayontopToggle(bool)));
	menu->addSeparator();
	
	QAction *herotrbt = menu->addAction(tr("Герой"));
	connect(herotrbt, SIGNAL(triggered()), this, SLOT(on_btInfo_pressed()));
	QAction *diarytrbt = menu->addAction(tr("Дневник"));
	connect(diarytrbt, SIGNAL(triggered()), this, SLOT(on_btDiary_pressed()));
	menu->addSeparator();

        settingsDialog = new Dialog(this);
        connect(settingsDialog,SIGNAL(accepted()),this,SLOT(updateSettings()));
        QAction *settingstrbt = menu->addAction(tr("Настройки"));
        connect(settingstrbt,SIGNAL(triggered()),this,SLOT(settings()));
        menu->addSeparator();
        //settingstrbt->setEnabled(false);
	
	QAction *exit = menu->addAction(tr("Выход"));
	connect(exit, SIGNAL(triggered()), qApp, SLOT(quit()));
	connect(exit, SIGNAL(triggered()), tray, SLOT(hide()));
	
	tray->setContextMenu(menu);
	
	//таймер
	timer = new QTimer(this);
	timer->start(15000);
	connect(timer, SIGNAL(timeout()), this, SLOT(update()));
	
        mess = new HeroMessager();

        QSettings settings("godville.net", "godvilleQT");
        restoreGeometry(settings.value("statWinGeometry").toByteArray());
        this->setWindowOpacity(settings.value("statWinOp",100).toInt()/100);
}
Esempio n. 4
0
void InitializationThread::initTranslations(void)
{
	//Search for language files
	const QDir qmDirectory(":/localization");
	const QStringList qmFiles = qmDirectory.entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);

	//Make sure we found at least one translation
	if(qmFiles.count() < 1)
	{
		qFatal("Could not find any translation files!");
		return;
	}

	//Initialize variables
	const QString langResTemplate(":/localization/%1.txt");
	QRegExp langIdExp("^LameXP_(\\w\\w)\\.qm$", Qt::CaseInsensitive);

	//Add all available translations
	for(QStringList::ConstIterator iter = qmFiles.constBegin(); iter != qmFiles.constEnd(); iter++)
	{
		const QString langFile = qmDirectory.absoluteFilePath(*iter);
		QString langId, langName;
		unsigned int systemId = 0, country = 0;
		
		if(QFileInfo(langFile).isFile() && (langIdExp.indexIn(*iter) >= 0))
		{
			langId = langIdExp.cap(1).toLower();
			QResource langRes = QResource(langResTemplate.arg(*iter));
			if(langRes.isValid() && langRes.size() > 0)
			{
				QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(langRes.data()), langRes.size());
				QTextStream stream(&data, QIODevice::ReadOnly);
				stream.setAutoDetectUnicode(false); stream.setCodec("UTF-8");

				while(!(stream.atEnd() || (stream.status() != QTextStream::Ok)))
				{
					QStringList langInfo = stream.readLine().simplified().split(",", QString::SkipEmptyParts);
					if(langInfo.count() >= 3)
					{
						systemId = langInfo.at(0).trimmed().toUInt();
						country  = langInfo.at(1).trimmed().toUInt();
						langName = langInfo.at(2).trimmed();
						break;
					}
				}
			}
		}

		if(!(langId.isEmpty() || langName.isEmpty() || (systemId == 0)))
		{
			if(MUtils::Translation::insert(langId, langFile, langName, systemId, country))
			{
				qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(*iter), MUTILS_UTF8(langName), systemId, country);
			}
			else
			{
				qWarning("Failed to register: %s", langFile.toLatin1().constData());
			}
		}
	}

	qDebug("All registered.\n");
}