Ejemplo n.º 1
0
QString transactionString(const QJsonObject& valueObject) {
    int sentCerts = valueObject["sent_certs"].toInt();
    int receivedCerts = valueObject["received_certs"].toInt();
    int sentMoney = valueObject["sent_money"].toInt();
    int receivedMoney = valueObject["received_money"].toInt();
    int dateInteger = valueObject["created_at"].toInt();
    QString message = valueObject["message"].toString();
    QDateTime createdAt(QDateTime::fromSecsSinceEpoch(dateInteger, Qt::UTC));
    QString result;

    if (sentCerts <= 0 && receivedCerts <= 0 && !KNOWN_USERS.contains(valueObject["sender_name"].toString())) {
        // this is an hfc transfer.
        if (sentMoney > 0) {
            QString recipient = userLink(valueObject["recipient_name"].toString(), valueObject["place_name"].toString());
            result += QString("Money sent to %1").arg(recipient);
        } else {
            QString sender = userLink(valueObject["sender_name"].toString(), valueObject["place_name"].toString());
            result += QString("Money from %1").arg(sender);
        }
        if (!message.isEmpty()) {
            result += QString("<br>with memo: <i>\"%1\"</i>").arg(message);
        }
    } else if (sentMoney <= 0 && receivedMoney <= 0 && (sentCerts > 0 || receivedCerts > 0) && !KNOWN_USERS.contains(valueObject["sender_name"].toString())) {
        // this is a non-HFC asset transfer.
        if (sentCerts > 0) {
            QString recipient = userLink(valueObject["recipient_name"].toString(), valueObject["place_name"].toString());
            result += QString("Gift sent to %1").arg(recipient);
        } else {
            QString sender = userLink(valueObject["sender_name"].toString(), valueObject["place_name"].toString());
            result += QString("Gift from %1").arg(sender);
        }
        if (!message.isEmpty()) {
            result += QString("<br>with memo: <i>\"%1\"</i>").arg(message);
        }
    } else {
        result += valueObject["message"].toString();
    }

    // no matter what we append a smaller date to the bottom of this...
    result += QString("<br><font size='-2' color='#1080B8'>%1").arg(createdAt.toLocalTime().toString(Qt::DefaultLocaleShortDate));
    return result;
}
Ejemplo n.º 2
0
void Image::postSaving(const QString &path, bool addMd5, bool startCommands, int count, bool basic)
{
	if (addMd5)
	{ m_profile->addMd5(md5(), path); }

	// Save info to a text file
	if (!basic)
	{
		auto logFiles = getExternalLogFiles(m_settings);
		for (auto it = logFiles.begin(); it != logFiles.end(); ++it)
		{
			auto logFile = it.value();
			QString textfileFormat = logFile["content"].toString();
			QStringList cont = this->path(textfileFormat, "", count, true, true, false, false, false);
			if (!cont.isEmpty())
			{
				int locationType = logFile["locationType"].toInt();
				QString contents = cont.first();

				// File path
				QString fileTagsPath;
				if (locationType == 0)
					fileTagsPath = this->path(logFile["filename"].toString(), logFile["path"].toString(), 0, true, false, true, true, true).first();
				else if (locationType == 1)
					fileTagsPath = logFile["uniquePath"].toString();
				else if (locationType == 2)
					fileTagsPath = path + logFile["suffix"].toString();

				// Replace some post-save tokens
				contents.replace("%path:nobackslash%", QDir::toNativeSeparators(path).replace("\\", "/"))
						.replace("%path%", QDir::toNativeSeparators(path));

				// Append to file if necessary
				QFile fileTags(fileTagsPath);
				bool append = fileTags.exists();
				if (fileTags.open(QFile::WriteOnly | QFile::Append | QFile::Text))
				{
					if (append)
						fileTags.write("\n");
					fileTags.write(contents.toUtf8());
					fileTags.close();
				}
			}
		}
	}

	// Keep original date
	if (m_settings->value("Save/keepDate", true).toBool())
		setFileCreationDate(path, createdAt());

	// Commands
	Commands &commands = m_profile->getCommands();
	if (startCommands)
	{ commands.before(); }
		for (const Tag &tag : qAsConst(m_tags))
		{ commands.tag(*this, tag, false); }
		commands.image(*this, path);
		for (const Tag &tag : qAsConst(m_tags))
		{ commands.tag(*this, tag, true); }
	if (startCommands)
	{ commands.after(); }

	setSavePath(path);
}