Skip to content

Commit

Permalink
update yandexnarodplugin
Browse files Browse the repository at this point in the history
  • Loading branch information
wadealer committed Feb 23, 2012
1 parent dc73639 commit 01ef309
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 18 deletions.
2 changes: 1 addition & 1 deletion generic/yandexnarodplugin/authmanager.cpp
Expand Up @@ -66,7 +66,7 @@ bool AuthManager::go(const QString& login, const QString& pass, const QString& c
narodPass = authdialog.getPasswd();
if (authdialog.getRemember()) {
o->setOption(CONST_LOGIN, narodLogin);
o->setOption(CONST_PASS, narodPass);
o->setOption(CONST_PASS, Options::encodePassword(narodPass));
}
post = "login=" + narodLogin.toLatin1() + "&passwd=" + narodPass.toLatin1();
}
Expand Down
9 changes: 9 additions & 0 deletions generic/yandexnarodplugin/changelog.txt
@@ -1,3 +1,12 @@
2012-02-23
v0.1.3
* при нажатии кнопки "В Броузер" теперь открывается ссылка http://narod.yandex.ru/disk/all/
* пароль теперь хранится в зашифрованном виде
* некоторые справления уи
* исправлены некоторые статусные сообщения в диалоге загрузки
* исправлено отображения файлов со спецсимволами в имени


2012-02-22
v0.1.2
* исправления для новой системы попапов
Expand Down
52 changes: 52 additions & 0 deletions generic/yandexnarodplugin/options.cpp
Expand Up @@ -19,6 +19,10 @@
#include "applicationinfoaccessinghost.h"
#include "optionaccessinghost.h"


static const QString passwordKey = "yandexnarodpluginkey";


Options * Options ::instance_ = 0;


Expand Down Expand Up @@ -153,3 +157,51 @@ QString Options::message(MessageType type)

return QString();
}

QString Options::encodePassword(const QString &pass)
{
QString result;
int n1, n2;

if (passwordKey.length() == 0) {
return pass;
}

for (n1 = 0, n2 = 0; n1 < pass.length(); ++n1) {
ushort x = pass.at(n1).unicode() ^ passwordKey.at(n2++).unicode();
QString hex;
hex.sprintf("%04x", x);
result += hex;
if(n2 >= passwordKey.length()) {
n2 = 0;
}
}
return result;
}

QString Options::decodePassword(const QString &pass)
{
QString result;
int n1, n2;

if (passwordKey.length() == 0) {
return pass;
}

for(n1 = 0, n2 = 0; n1 < pass.length(); n1 += 4) {
ushort x = 0;
if(n1 + 4 > pass.length()) {
break;
}
x += QString(pass.at(n1)).toInt(NULL,16)*4096;
x += QString(pass.at(n1+1)).toInt(NULL,16)*256;
x += QString(pass.at(n1+2)).toInt(NULL,16)*16;
x += QString(pass.at(n1+3)).toInt(NULL,16);
QChar c(x ^ passwordKey.at(n2++).unicode());
result += c;
if(n2 >= passwordKey.length()) {
n2 = 0;
}
}
return result;
}
8 changes: 6 additions & 2 deletions generic/yandexnarodplugin/options.h
Expand Up @@ -25,13 +25,14 @@ class OptionAccessingHost;

#define CONST_COOKIES "cookies"
#define CONST_LOGIN "login"
#define CONST_PASS "pass"
#define CONST_PASS_OLD "pass"
#define CONST_PASS "pass-encoded"
#define CONST_TEMPLATE "template"
#define CONST_LAST_FOLDER "lastfolder"
#define CONST_WIDTH "width"
#define CONST_HEIGHT "height"
#define POPUP_OPTION_NAME ".popupinterval"
#define VERSION "0.1.2"
#define VERSION "0.1.3"


#define O_M(x) Options::message(x)
Expand All @@ -46,6 +47,9 @@ class Options : public QObject
static void reset();
static QString message(MessageType type);

static QString encodePassword(const QString &pass);
static QString decodePassword(const QString &pass);

void setApplicationInfoAccessingHost(ApplicationInfoAccessingHost* host);
void setOptionAccessingHost(OptionAccessingHost* host);
void setOption(const QString& name, const QVariant& value);
Expand Down
2 changes: 1 addition & 1 deletion generic/yandexnarodplugin/uploaddialog.cpp
Expand Up @@ -79,7 +79,7 @@ void uploadDialog::progress(qint64 cBytes, qint64 totalBytes)
ui.labelSpeed->setText(tr("Speed: ")+QString::number(speed_kbsec)+tr(" kb/sec"));

if (cBytes == totalBytes)
ui.labelStatus->setText(tr("Upload complete."));
ui.labelStatus->setText(tr("Upload completed. Waiting for verification."));
}

void uploadDialog::setDone()
Expand Down
2 changes: 1 addition & 1 deletion generic/yandexnarodplugin/uploadmanager.cpp
Expand Up @@ -208,7 +208,7 @@ void UploadManager::go(const QString& file)
AuthManager am;
emit statusText(O_M(MAuthStart));
bool auth = am.go(Options::instance()->getOption(CONST_LOGIN, "").toString(),
Options::instance()->getOption(CONST_PASS, "").toString() );
Options::decodePassword(Options::instance()->getOption(CONST_PASS, "").toString()) );
if(auth) {
setCookies(am.cookies());
Options::instance()->saveCookies(am.cookies());
Expand Down
7 changes: 7 additions & 0 deletions generic/yandexnarodplugin/yandexnarod.cpp
Expand Up @@ -75,6 +75,13 @@ bool yandexnarodPlugin::enable()
Options::instance()->setApplicationInfoAccessingHost(appInfo);
Options::instance()->setOptionAccessingHost(psiOptions);

//remove old password option
QString oldPass = Options::instance()->getOption(CONST_PASS_OLD).toString();
if(!oldPass.isEmpty()) {
Options::instance()->setOption(CONST_PASS_OLD, QVariant(""));
Options::instance()->setOption(CONST_PASS, Options::encodePassword(oldPass));
}

popupId = popup->registerOption(name(), 3, "plugins.options." + shortName() + POPUP_OPTION_NAME);

return enabled;
Expand Down
2 changes: 1 addition & 1 deletion generic/yandexnarodplugin/yandexnarodmanage.cpp
Expand Up @@ -294,7 +294,7 @@ void yandexnarodManage::on_btnClearCookies_clicked()

void yandexnarodManage::on_btnOpenBrowser_clicked()
{
QDesktopServices::openUrl(QUrl("http://narod.yandex.ru"));
QDesktopServices::openUrl(QUrl("http://narod.yandex.ru/disk/all/"));
}

void yandexnarodManage::on_listWidget_pressed(QModelIndex)
Expand Down
34 changes: 26 additions & 8 deletions generic/yandexnarodplugin/yandexnarodmanage.ui
Expand Up @@ -28,7 +28,7 @@
<item>
<widget class="QPushButton" name="btnReload">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -57,11 +57,23 @@
<item>
<widget class="QPushButton" name="btnUpload">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>170</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>170</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Upload File</string>
</property>
Expand All @@ -74,20 +86,20 @@
<item>
<widget class="QFrame" name="frameFileActions">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<width>170</width>
<height>98</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<width>170</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -104,7 +116,7 @@
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -217,15 +229,21 @@
</item>
<item>
<widget class="QFrame" name="frameProgress">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<width>170</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<width>170</width>
<height>50</height>
</size>
</property>
Expand Down
6 changes: 4 additions & 2 deletions generic/yandexnarodplugin/yandexnarodnetman.cpp
Expand Up @@ -184,7 +184,7 @@ void yandexnarodNetMan::netmanDo(QList<FileItem> fileItems)
QList<QNetworkCookie> cookList = netcookjar->cookiesForUrl(mainUrl);
if (cookList.isEmpty()) {
bool auth = startAuth(Options::instance()->getOption(CONST_LOGIN, "").toString(),
Options::instance()->getOption(CONST_PASS, "").toString() );
Options::decodePassword(Options::instance()->getOption(CONST_PASS, "").toString()) );

if(!auth)
return;
Expand Down Expand Up @@ -292,7 +292,9 @@ void yandexnarodNetMan::netrpFinished(QNetworkReply* reply)
cpos = rx.indexIn(page);
while (cpos != -1) {
FileItem fileitem;
fileitem.filename = QString::fromUtf8(rx.cap(5).toLatin1());
QTextDocument doc;
doc.setHtml(QString::fromUtf8(rx.cap(5).toLatin1()));
fileitem.filename = doc.toPlainText();
fileitem.fileid = rx.cap(2);
fileitem.token = rx.cap(3);
fileitem.fileurl = rx.cap(4);
Expand Down
4 changes: 2 additions & 2 deletions generic/yandexnarodplugin/yandexnarodsettings.cpp
Expand Up @@ -39,7 +39,7 @@ void yandexnarodSettings::saveSettings()
{
Options* o = Options::instance();
o->setOption(CONST_LOGIN, ui.editLogin->text());
o->setOption(CONST_PASS, ui.editPasswd->text());
o->setOption(CONST_PASS, Options::encodePassword(ui.editPasswd->text()));
o->setOption(CONST_TEMPLATE, ui.textTpl->toPlainText());
}

Expand All @@ -52,7 +52,7 @@ void yandexnarodSettings::restoreSettings()
{
Options* o = Options::instance();
ui.editLogin->setText(o->getOption(CONST_LOGIN).toString());
ui.editPasswd->setText(o->getOption(CONST_PASS).toString());
ui.editPasswd->setText(Options::decodePassword(o->getOption(CONST_PASS).toString()));
ui.textTpl->setText(o->getOption(CONST_TEMPLATE, QVariant("File sent: %N (%S bytes)\n%U")).toString());
}

Expand Down

0 comments on commit 01ef309

Please sign in to comment.