/guitone-1.0rc5/src/monotone/MonotoneResourceFile.cpp
# · C++ · 77 lines · 50 code · 10 blank · 17 comment · 2 complexity · 27a6405d9e69c086cb70312b2bd10058 MD5 · raw file
- /***************************************************************************
- * Copyright (C) 2010 by Thomas Keller *
- * me@thomaskeller.biz *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
- ***************************************************************************/
- #include "MonotoneResourceFile.h"
- #include "Platform.h"
- #include "Settings.h"
- #include <QDir>
- #include <QDateTime>
- #include <QCryptographicHash>
- MonotoneResourceFile::MonotoneResourceFile() : QFile(0)
- {
- QByteArray data;
- data.append(QDateTime::currentDateTime().toString());
- data.append(Platform::getUsername());
- QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
- QString tempPath = QDir::tempPath();
- tempPath.append(QDir::separator()).append(hash.toHex()).append(".lua");
- setFileName(tempPath);
- open(QIODevice::ReadWrite);
- setPermissions(QFile::ReadOwner | QFile::WriteOwner);
- write(
- "-- this is an automatically created configuration file\n"
- "-- for a running monotone instance of guitone\n\n"
- );
- QMap<QString, QVariant> keyPasswords = Settings::getItemMap("KeyPasswords");
- if (keyPasswords.size() > 0)
- {
- write("if type(get_passphrase) == 'function' then\n");
- write(" old_get_passphrase = get_passphrase\n");
- write("end\n\n");
- write("function get_passphrase(key_identity)\n");
- write(" if type(old_get_passphrase) == 'function' then\n");
- write(" phrase = old_get_passphrase(key_identity)\n");
- write(" if phrase ~= nil then\n");
- write(" return phrase\n");
- write(" end\n");
- write(" end\n");
- QMapIterator<QString, QVariant> it(keyPasswords);
- while (it.hasNext())
- {
- it.next();
- write(" if key_identity.id == \"" + it.key().toUtf8() + "\" then\n");
- write(" return \"" + it.value().toString().toUtf8() + "\"\n");
- write(" end\n");
- }
- write("end\n");
- }
- close();
- }
- MonotoneResourceFile::~MonotoneResourceFile()
- {
- remove();
- }