support edit account host address
This commit is contained in:
parent
5d9edb6d22
commit
82ca1283d8
10 changed files with 306 additions and 0 deletions
|
@ -72,6 +72,7 @@ SET(moc_headers
|
|||
src/ui/main-window.h
|
||||
src/ui/init-seafile-dialog.h
|
||||
src/ui/login-dialog.h
|
||||
src/ui/account-settings-dialog.h
|
||||
src/ui/create-repo-dialog.h
|
||||
src/ui/repo-detail-dialog.h
|
||||
src/ui/settings-dialog.h
|
||||
|
@ -112,6 +113,7 @@ ENDIF()
|
|||
# UI FILES
|
||||
SET(ui_files
|
||||
ui/login-dialog.ui
|
||||
ui/account-settings-dialog.ui
|
||||
ui/create-repo-dialog.ui
|
||||
ui/repo-detail-dialog.ui
|
||||
ui/settings-dialog.ui
|
||||
|
@ -203,6 +205,7 @@ SET(seafile_client_sources
|
|||
src/ui/main-window.cpp
|
||||
src/ui/init-seafile-dialog.cpp
|
||||
src/ui/login-dialog.cpp
|
||||
src/ui/account-settings-dialog.cpp
|
||||
src/ui/repo-detail-dialog.cpp
|
||||
src/ui/settings-dialog.cpp
|
||||
src/ui/create-repo-dialog.cpp
|
||||
|
|
|
@ -144,3 +144,41 @@ bool AccountManager::setCurrentAccount(const Account& account)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
int AccountManager::replaceAccount(const Account& old_account, const Account& new_account)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < accounts_.size(); i++) {
|
||||
if (accounts_[i].serverUrl == old_account.serverUrl
|
||||
&& accounts_[i].username == old_account.username) {
|
||||
accounts_.erase(accounts_.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
accounts_.insert(accounts_.begin(), new_account);
|
||||
|
||||
QString old_url = old_account.serverUrl.toEncoded().data();
|
||||
QString new_url = new_account.serverUrl.toEncoded().data();
|
||||
|
||||
qint64 timestamp = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
QString sql =
|
||||
"UPDATE Accounts "
|
||||
"SET url = %1, "
|
||||
" username = %2, "
|
||||
" token = %3, "
|
||||
" lastVisited = %4 "
|
||||
"WHERE url = %5 "
|
||||
" AND username = %2";
|
||||
|
||||
sql = sql.arg(new_url).arg(new_account.username). \
|
||||
arg(new_account.token).arg(QString::number(timestamp)) \
|
||||
.arg(old_url);
|
||||
|
||||
sqlite_query_exec (db, toCStr(sql));
|
||||
|
||||
emit accountsChanged();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
|
||||
bool setCurrentAccount(const Account& account);
|
||||
|
||||
int replaceAccount(const Account& old_account,
|
||||
const Account& new_account);
|
||||
|
||||
// accessors
|
||||
const std::vector<Account>& accounts() const { return accounts_; }
|
||||
signals:
|
||||
|
|
|
@ -667,3 +667,25 @@ QString SeafileRpcClient::getCcnetPeerId()
|
|||
{
|
||||
return sync_client_ ? sync_client_->base.id : "";
|
||||
}
|
||||
|
||||
int SeafileRpcClient::updateReposServerHost(const QString& old_host,
|
||||
const QString& new_host,
|
||||
QString *err)
|
||||
{
|
||||
GError *error = NULL;
|
||||
int ret = searpc_client_call__int (seafile_rpc_client_,
|
||||
"seafile_update_repos_server_host",
|
||||
&error, 2,
|
||||
"string", toCStr(old_host),
|
||||
"string", toCStr(new_host));
|
||||
|
||||
if (ret < 0) {
|
||||
if (error) {
|
||||
*err = QString::fromUtf8(error->message);
|
||||
} else {
|
||||
*err = tr("Unknown error");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -80,6 +80,10 @@ public:
|
|||
|
||||
QString getCcnetPeerId();
|
||||
|
||||
int updateReposServerHost(const QString& old_host,
|
||||
const QString& new_host,
|
||||
QString *err);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(SeafileRpcClient)
|
||||
|
||||
|
|
86
src/ui/account-settings-dialog.cpp
Normal file
86
src/ui/account-settings-dialog.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include <QtGui>
|
||||
|
||||
#include "settings-mgr.h"
|
||||
#include "account-mgr.h"
|
||||
#include "seafile-applet.h"
|
||||
#include "rpc/rpc-client.h"
|
||||
#include "account-settings-dialog.h"
|
||||
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
AccountSettingsDialog::AccountSettingsDialog(const Account& account, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
account_(account)
|
||||
{
|
||||
setupUi(this);
|
||||
setWindowTitle(tr("Account Settings"));
|
||||
setWindowIcon(QIcon(":/images/seafile.png"));
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
mServerAddr->setText(account_.serverUrl.toString());
|
||||
mUsername->setText(account_.username);
|
||||
mUsername->setEnabled(false);
|
||||
|
||||
connect(mOkBtn, SIGNAL(clicked()), this, SLOT(onSubmitBtnClicked()));
|
||||
|
||||
// const QRect screen = QApplication::desktop()->screenGeometry();
|
||||
// move(screen.center() - this->rect().center());
|
||||
}
|
||||
|
||||
void AccountSettingsDialog::showWarning(const QString& msg)
|
||||
{
|
||||
seafApplet->warningBox(msg, this);
|
||||
}
|
||||
|
||||
bool AccountSettingsDialog::validateInputs()
|
||||
{
|
||||
QString server_addr = mServerAddr->text().trimmed();
|
||||
QUrl url;
|
||||
|
||||
if (server_addr.size() == 0) {
|
||||
showWarning(tr("Please enter the server address"));
|
||||
return false;
|
||||
} else {
|
||||
if (!server_addr.startsWith("http://") && !server_addr.startsWith("https://")) {
|
||||
showWarning(tr("%1 is not a valid server address").arg(server_addr));
|
||||
return false;
|
||||
}
|
||||
|
||||
url = QUrl(server_addr, QUrl::StrictMode);
|
||||
if (!url.isValid()) {
|
||||
showWarning(tr("%1 is not a valid server address").arg(server_addr));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AccountSettingsDialog::onSubmitBtnClicked()
|
||||
{
|
||||
if (!validateInputs()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString url = mServerAddr->text().trimmed();
|
||||
if (url != account_.serverUrl.toString()) {
|
||||
Account new_account(account_);
|
||||
new_account.serverUrl = url;
|
||||
if (seafApplet->accountManager()->replaceAccount(account_,
|
||||
new_account) < 0) {
|
||||
showWarning(tr("Failed to save account information"));
|
||||
return;
|
||||
}
|
||||
QString error;
|
||||
if (seafApplet->rpcClient()->updateReposServerHost(account_.serverUrl.host(),
|
||||
new_account.serverUrl.host(), &error) < 0) {
|
||||
showWarning(tr("Failed to save the changes: %1").arg(error));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
seafApplet->messageBox(tr("Successfully updated current account information"), this);
|
||||
accept();
|
||||
}
|
30
src/ui/account-settings-dialog.h
Normal file
30
src/ui/account-settings-dialog.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef SEAFILE_CLIENT_ACCOUNT_SETTINGS_H
|
||||
#define SEAFILE_CLIENT_ACCOUNT_SETTINGS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "ui_account-settings-dialog.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
|
||||
#include "account.h"
|
||||
|
||||
class AccountSettingsDialog : public QDialog,
|
||||
public Ui::AccountSettingsDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AccountSettingsDialog(const Account& account, QWidget *parent=0);
|
||||
|
||||
private slots:
|
||||
void onSubmitBtnClicked();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(AccountSettingsDialog);
|
||||
bool validateInputs();
|
||||
void showWarning(const QString& msg);
|
||||
|
||||
Account account_;
|
||||
};
|
||||
|
||||
#endif // SEAFILE_CLIENT_ACCOUNT_SETTINGS_H
|
|
@ -1,12 +1,14 @@
|
|||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QToolButton>
|
||||
#include <QScopedPointer>
|
||||
|
||||
#include "account.h"
|
||||
#include "account.h"
|
||||
#include "seafile-applet.h"
|
||||
#include "account-mgr.h"
|
||||
#include "login-dialog.h"
|
||||
#include "account-settings-dialog.h"
|
||||
#include "rpc/rpc-client.h"
|
||||
#include "main-window.h"
|
||||
#include "init-vdrive-dialog.h"
|
||||
|
@ -67,6 +69,15 @@ void AccountView::deleteAccount()
|
|||
}
|
||||
}
|
||||
|
||||
void AccountView::editAccountSettings()
|
||||
{
|
||||
const Account& account = seafApplet->accountManager()->currentAccount();
|
||||
|
||||
AccountSettingsDialog dialog(account, this);
|
||||
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void AccountView::updateAccountInfoDisplay()
|
||||
{
|
||||
if (seafApplet->accountManager()->hasAccount()) {
|
||||
|
@ -113,6 +124,14 @@ void AccountView::onAccountChanged()
|
|||
account_menu_->addSeparator();
|
||||
}
|
||||
|
||||
if (!accounts.empty()) {
|
||||
account_settings_action_ = new QAction(tr("Edit account settings"), this);
|
||||
account_settings_action_->setIcon(::getIconByDPI(":/images/edit.png"));
|
||||
account_settings_action_->setIconVisibleInMenu(true);
|
||||
connect(account_settings_action_, SIGNAL(triggered()), this, SLOT(editAccountSettings()));
|
||||
account_menu_->addAction(account_settings_action_);
|
||||
}
|
||||
|
||||
// Add rest items
|
||||
add_account_action_ = new QAction(tr("Add an account"), this);
|
||||
add_account_action_->setIcon(::getIconByDPI(":/images/plus.png"));
|
||||
|
|
|
@ -22,6 +22,7 @@ public slots:
|
|||
void onAccountChanged();
|
||||
void showAddAccountDialog();
|
||||
void deleteAccount();
|
||||
void editAccountSettings();
|
||||
void onAccountItemClicked();
|
||||
|
||||
private slots:
|
||||
|
@ -35,6 +36,7 @@ private:
|
|||
|
||||
// Account operations
|
||||
QAction *add_account_action_;
|
||||
QAction *account_settings_action_;
|
||||
QAction *delete_account_action_;
|
||||
QMenu *account_menu_;
|
||||
};
|
||||
|
|
99
ui/account-settings-dialog.ui
Normal file
99
ui/account-settings-dialog.ui
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AccountSettingsDialog</class>
|
||||
<widget class="QDialog" name="AccountSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>483</width>
|
||||
<height>123</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Server Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="mServerAddr"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Email</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="mUsername"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mOkBtn">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mCancelBtn">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>mOkBtn</zorder>
|
||||
<zorder>mServerAddr</zorder>
|
||||
<zorder>mUsername</zorder>
|
||||
<zorder>label</zorder>
|
||||
<zorder>label_2</zorder>
|
||||
<zorder></zorder>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>mCancelBtn</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>AccountSettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>472</x>
|
||||
<y>108</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>249</x>
|
||||
<y>122</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
Add table
Add a link
Reference in a new issue