예제 #1
0
bool LoggerPlugin::load()
{
	if (m_settingsItem)
		return false;
	Config config = Config().group(QLatin1String("Logger"));
	QString path = config.value(QLatin1String("path"),
								SystemInfo::getPath(SystemInfo::ConfigDir).append("/qutim.log"));
	bool enable = config.value(QLatin1String("enable"), false);
	reloadSettings();
	qInstallMsgHandler(SimpleLoggingHandler);
	debug() << tr("New session started, happy debuging ^_^");

	AutoSettingsItem *settingsItem = new AutoSettingsItem(Settings::Plugin,
														  Icon("view-choose"),
														  QT_TRANSLATE_NOOP("Plugin", "Logger"));
	settingsItem->connect(SIGNAL(saved()), this, SLOT(reloadSettings()));
	settingsItem->setConfig(QString(), "Logger");
	ObjectGenerator *gen = new GeneralGenerator<AutoSettingsFileChooser>();
	AutoSettingsItem::Entry *entryItem = settingsItem->addEntry(QT_TRANSLATE_NOOP("Plugin", "Select log path"), gen);
	entryItem->setProperty("path", path);
	entryItem->setName("path");
	gen = new GeneralGenerator<QCheckBox>();
	entryItem = settingsItem->addEntry(QT_TRANSLATE_NOOP("Plugin", "Enable dump of debug info"), gen);
	entryItem->setProperty("checked", enable);
	entryItem->setName("enable");
	m_settingsItem = settingsItem;
	Settings::registerItem(settingsItem);
	return true;
}
예제 #2
0
QScriptValue scriptSettingsRegister(QScriptContext *ctxt, QScriptEngine *e)
{
	if (ctxt->argumentCount() != 1)
		return ctxt->throwError("register() takes exactly one argument");
	QScriptValue item = ctxt->argument(0);
	Settings::Type itemType = static_cast<Settings::Type>(item.property("type").toInt32());
	QString icon = item.property("icon").toString();
	LocalizedString text = qscriptvalue_cast<LocalizedString>(item.property("text"));
	AutoSettingsItem *settingsItem = new AutoSettingsItem(itemType, Icon(icon), text);
	settingsItem->setConfig(QString(), QLatin1String("plugins/script/")
							+ static_cast<ScriptEngine*>(e)->name());
	QScriptValue onSaved = item.property("onSaved");
	if (onSaved.isFunction()) {
		ScriptSettingsConnector *helper = new ScriptSettingsConnector(e);
		settingsItem->connect(SIGNAL(saved()), helper, SLOT(onSaved()));
		qScriptConnect(helper, SIGNAL(saved()), item, onSaved);
	}

	QScriptValue entries = item.property("entries");
	quint32 len = entries.property(QLatin1String("length")).toUInt32();
	for (quint32 i = 0; i < len; ++i) {
		QScriptValue entry = entries.property(i);
		text = qscriptvalue_cast<LocalizedString>(entry.property("text"));
		ObjectGenerator *gen = 0;
		QString type = entry.property("type").toString();
		if (type == QLatin1String("CheckBox"))
			gen = new GeneralGenerator<QCheckBox>();
		else if (type == QLatin1String("ComboBox"))
			gen = new GeneralGenerator<AutoSettingsComboBox>();
		else if (type == QLatin1String("LineEdit"))
			gen = new GeneralGenerator<QLineEdit>();
		else if (type == QLatin1String("TextEdit"))
			gen = new GeneralGenerator<QTextEdit>();
		else if (type == QLatin1String("PlainTextEdit"))
			gen = new GeneralGenerator<QPlainTextEdit>();
		else
			continue;
		AutoSettingsItem::Entry *entryItem = settingsItem->addEntry(text, gen);
		QScriptValueIterator it(entry);
		while (it.hasNext()) {
			it.next();
			if (it.name() == QLatin1String("type") || it.name() == QLatin1String("text"))
				continue;
			else if (it.name() == QLatin1String("name"))
				entryItem->setName(it.value().toString());
			else
				entryItem->setProperty(it.name().toUtf8().constData(), it.value().toVariant());
		}
	}
	Settings::registerItem(settingsItem);
	return QScriptValue();
}