diff --git a/fileio.cpp b/fileio.cpp new file mode 100644 index 0000000..9793d60 --- /dev/null +++ b/fileio.cpp @@ -0,0 +1,73 @@ +#include "fileio.h" +#include +#include + +FileIO::FileIO(QObject *parent) : + QObject(parent) +{ + +} + +QString FileIO::read() +{ + if (mSource.isEmpty()){ + emit error("source is empty"); + return QString(); + } + + QFile file(mSource); + QString fileContent; + if ( file.open(QIODevice::ReadOnly) ) { + QString line; + QTextStream t( &file ); + do { + line = t.readLine(); + fileContent += line; + } while (!line.isNull()); + + file.close(); + } else { + emit error("Unable to open the file"); + return QString(); + } + return fileContent; +} + +bool FileIO::write(const QString& data) +{ + if (mSource.isEmpty()) + return false; + + QFile file(mSource); + if (!file.open(QFile::WriteOnly | QFile::Truncate)) + return false; + + QTextStream out(&file); + out << data; + + file.close(); + + return true; +} + +bool FileIO::exists() +{ + if (mSource.isEmpty()) { + emit error("Source is empty!"); + return false; + } + + QFile file(mSource); + return file.exists(); +} + +bool FileIO::exists(const QString& filename) +{ + if (filename.isEmpty()) { + emit error("Source is empty!"); + return false; + } + + QFile file(filename); + return file.exists(); +} diff --git a/fileio.h b/fileio.h new file mode 100644 index 0000000..e8c67c2 --- /dev/null +++ b/fileio.h @@ -0,0 +1,35 @@ +#ifndef FILEIO_H +#define FILEIO_H + +#include + +class FileIO : public QObject +{ + Q_OBJECT + +public: + Q_PROPERTY(QString source + READ source + WRITE setSource + NOTIFY sourceChanged) + explicit FileIO(QObject *parent = 0); + + Q_INVOKABLE QString read(); + Q_INVOKABLE bool write(const QString& data); + Q_INVOKABLE bool exists(); + Q_INVOKABLE bool exists(const QString& filename); + + QString source() { return mSource; }; + +public slots: + void setSource(const QString& source) { mSource = source; }; + +signals: + void sourceChanged(const QString& source); + void error(const QString& msg); + +private: + QString mSource; +}; + +#endif // FILEIO_H diff --git a/qml/lib/urldecoder.js b/qml/lib/urldecoder.js index 212c545..552df7b 100644 --- a/qml/lib/urldecoder.js +++ b/qml/lib/urldecoder.js @@ -6,7 +6,7 @@ function decode(url) { if (url.search(/^otpauth:\/\/[th]otp\/.*?.*/) != -1) { var ret = {"type": "", "title": "", "secret": "", "counter": ""}; ret.type = url.slice(10,14).toUpperCase(); - ret.title = url.slice(15, url.indexOf("?")); + ret.title = decodeURIComponent(url.slice(15, url.indexOf("?"))); var pstr = url.slice(url.indexOf("?")+1, url.length); var params = pstr.split("&"); diff --git a/rpm/harbour-sailotp.changes b/rpm/harbour-sailotp.changes index 67517f0..294f52e 100644 --- a/rpm/harbour-sailotp.changes +++ b/rpm/harbour-sailotp.changes @@ -1,2 +1,5 @@ +* Fri May 22 2015 Stefan Brand 1.1-1 +- Added URL-decoding for OTP-titles when scanning QR-codes + * Tue Jul 01 2014 Stefan Brand 1.0-1 - Added harbour-compatible QR-Reader diff --git a/rpm/harbour-sailotp.yaml b/rpm/harbour-sailotp.yaml index 65a9844..f481a35 100644 --- a/rpm/harbour-sailotp.yaml +++ b/rpm/harbour-sailotp.yaml @@ -1,7 +1,7 @@ Name: harbour-sailotp Summary: SailOTP -Version: 1.0 -Release: 2 +Version: 1.1 +Release: 1 Group: Security URL: https://github.com/seiichiro0185/sailotp/ License: "BSD\t"