1
0
Fork 0
mirror of https://github.com/seiichiro0185/sailotp.git synced 2024-11-21 23:39:41 +00:00

Version 1.1

Added URL-decoding for OTP-titles when scanning QR-codes.
Fixes github issue #4
This commit is contained in:
seiichiro 2015-05-22 19:09:07 +02:00
parent e2e3fd71c8
commit 8725b13639
5 changed files with 114 additions and 3 deletions

73
fileio.cpp Normal file
View file

@ -0,0 +1,73 @@
#include "fileio.h"
#include <QFile>
#include <QTextStream>
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();
}

35
fileio.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef FILEIO_H
#define FILEIO_H
#include <QObject>
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

View file

@ -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("&");

View file

@ -1,2 +1,5 @@
* Fri May 22 2015 Stefan Brand <sailfish@seiichiro0185.org> 1.1-1
- Added URL-decoding for OTP-titles when scanning QR-codes
* Tue Jul 01 2014 Stefan Brand <sailfish@seiichiro0185.org> 1.0-1
- Added harbour-compatible QR-Reader

View file

@ -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"