Exemple #1
0
void WAccount::fillStrings(QString &text, QString &html, const QDomElement &element, const QString &prefix)
{
	QString key = prefix + QLatin1Char('%');
	if (key != QLatin1String("%%")) {
		text.replace(key, element.text());
		html.replace(key, element.text().toHtmlEscaped());
		qDebug() << key;
	}
	key.chop(1);

	QDomNamedNodeMap attributes = element.attributes();
	for (int i = 0; i < attributes.count(); ++i) {
		QDomNode attribute = attributes.item(i);
		QString attributeKey = key
				% QLatin1Char('/')
				% attribute.nodeName()
				% QLatin1Char('%');
		qDebug() << attributeKey;
		text.replace(attributeKey, attribute.nodeValue());
		html.replace(attributeKey, attribute.nodeValue().toHtmlEscaped());
	}

	if (!key.endsWith(QLatin1Char('%')))
		key += QLatin1Char('/');
	QDomNodeList elementChildren = element.childNodes();
	for (int i = 0; i < elementChildren.count(); ++i) {
		QDomNode node = elementChildren.at(i);
		if (node.isElement())
			fillStrings(text, html, node.toElement(), key + node.nodeName());
	}
}
Exemple #2
0
void StringSelector::newString() {
  QString stringName;
  DialogLauncher::self()->showStringDialog(stringName, 0, true);
  fillStrings();
  StringPtr string = kst_cast<String>(_store->retrieveObject(stringName));

  if (string) {
    setSelectedString(string);
    emitSelectionChanged();
  }
}
/**
 * Different constructor
 * @param startOnMonday Does the week start on monday?
 * @param rp Already set ORecur object
 * @param startDate The start date
 * @param parent The parent widget
 * @param name The name of the object
 * @param modal
 * @param fl The flags for window
 */
ORecurranceWidget::ORecurranceWidget( bool startOnMonday,
                                      const ORecur& rp, const QDate& startDate,
                                      QWidget* parent, const char* name,
                                      bool modal, WFlags fl)
    : ORecurranceBase( parent, name, modal, fl ),
      start( startDate ),
      end( rp.endDate() ),
      startWeekOnMonday( startOnMonday )
{
     if (strDayTemplate.isEmpty() )
        fillStrings();
    // do some stuff with the repeat pattern
    init();
    setRecurrence( rp );
}
/**
 * Constructs the Widget
 * @param startOnMonday Does the week start on monday
 * @param newStart The start date of the recurrence
 * @param parent The parent widget
 * @param name the name of object
 * @param modal if the dialog should be modal
 * @param fl Additional window flags
 */
ORecurranceWidget::ORecurranceWidget( bool startOnMonday,
                                      const QDate& newStart,
                                      QWidget* parent,
                                      const char* name,
                                      bool modal,
                                      WFlags fl )
    : ORecurranceBase( parent, name, modal, fl ),
      start( newStart ),
      currInterval( None ),
      startWeekOnMonday( startOnMonday )
{
     if (strDayTemplate.isEmpty() )
        fillStrings();

    init();
    fraType->setButton( currInterval );
    chkNoEnd->setChecked( TRUE );
    setupNone();
}
Exemple #5
0
StringSelector::StringSelector(QWidget *parent, ObjectStore *store)
  : QWidget(parent), _allowEmptySelection(false), _store(store) {

  setupUi(this);

  int size = style()->pixelMetric(QStyle::PM_SmallIconSize);

  _newString->setIcon(KstGetIcon("kst_stringnew"));
  _editString->setIcon(KstGetIcon("kst_stringedit"));

  _newString->setFixedSize(size + 8, size + 8);
  _editString->setFixedSize(size + 8, size + 8);
  _selectString->setFixedSize(size + 8, size + 8);

  fillStrings();

  connect(_newString, SIGNAL(pressed()), this, SLOT(newString()));
  connect(_editString, SIGNAL(pressed()), this, SLOT(editString()));
  connect(_string, SIGNAL(currentIndexChanged(int)), this, SLOT(emitSelectionChanged()));
  connect(_string, SIGNAL(currentIndexChanged(int)), this, SLOT(updateDescriptionTip()));
}
Exemple #6
0
void StringSelector::editString() {
  QString stringName;
  DialogLauncher::self()->showStringDialog(stringName, ObjectPtr(selectedString()), true);
  fillStrings();
}
Exemple #7
0
void StringSelector::setObjectStore(ObjectStore *store) {
  _store = store;
  fillStrings();
}
Exemple #8
0
void WAccount::onNetworkReply(QNetworkReply *reply)
{
	reply->deleteLater();
	WContact *contact = qobject_cast<WContact*>(reply->request().originatingObject());
	if (!contact)
		return;

	QDomDocument doc;
	if (!doc.setContent(reply->readAll()))
		return;
	bool needMessage = reply->property("needMessage").toBool();
	QDomElement rootElement = doc.documentElement();

	QDomElement units = rootElement.namedItem(QLatin1String("units")).toElement();
	QString tempUnit = units.namedItem(QLatin1String("temp")).toElement().text();

	QDomElement local = rootElement.namedItem(QLatin1String("local")).toElement();
	QString cityName = local.namedItem(QLatin1String("city")).toElement().text();
	contact->setNameInternal(cityName);

	QDomElement current = rootElement.namedItem(QLatin1String("current")).toElement();
	if (!current.isNull()) {
		QString temperature = current.namedItem(QLatin1String("temperature")).toElement().text();
		QString iconId = current.namedItem(QLatin1String("weathericon")).toElement().text();
		QString text = tr("Weather: %1°%2").arg(temperature, tempUnit);
		contact->setStatusInternal(iconId, text);
		if (needMessage) {
			QString text = loadResourceFile(QLatin1String("Current.txt"));
			QString html = loadResourceFile(QLatin1String("Current.html"));

			fillStrings(text, html, units, QLatin1String("%units"));
			fillStrings(text, html, current, QLatin1String("%"));

			Message message(text);
			message.setHtml(html);
			message.setChatUnit(contact);
			message.setIncoming(true);
			message.setTime(QDateTime::currentDateTime());
			ChatLayer::get(contact, true)->appendMessage(message);
		}
	}

	QDomElement forecast = rootElement.namedItem(QLatin1String("forecast")).toElement();
	if (needMessage && !forecast.isNull()) {
		QString textResult = loadResourceFile(QLatin1String("ForecastTitle.txt"));
		QString htmlResult = loadResourceFile(QLatin1String("ForecastTitle.html"));
		QString textBody = loadResourceFile(QLatin1String("ForecastDay.txt"));
		QString htmlBody = loadResourceFile(QLatin1String("ForecastDay.html"));

		fillStrings(textBody, htmlBody, units, QLatin1String("%units"));

		QDomNodeList days = forecast.elementsByTagName(QLatin1String("day"));
		for (int i = 0; i < days.count(); ++i) {
			if (!days.at(i).isElement())
				continue;
			QDomElement day = days.at(i).toElement();
			QString text = textBody;
			QString html = htmlBody;
			fillStrings(text, html, day, QLatin1String("%"));
			textResult += text;
			htmlResult += html;
		}

		Message message(textResult);
		message.setHtml(htmlResult);
		message.setChatUnit(contact);
		message.setIncoming(true);
		message.setTime(QDateTime::currentDateTime());
		ChatLayer::get(contact, true)->appendMessage(message);
	}
}