Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple accounts on linux #404

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/account-mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ int AccountManager::resyncAccount(const Account& account)

#if defined(Q_OS_WIN32)
setAccountSyncRoot(updated_account);
#elif defined(Q_OS_LINUX)
setAccountDisplayName(updated_account);
#endif

SeafileRpcClient *rpc_client = gui->rpcClient(updated_account.domainID());
Expand Down Expand Up @@ -631,6 +633,10 @@ void AccountManager::addAccountToDaemon(const Account& account)
gui->fileProviderManager()->registerDomain(added_account);
gui->fileProviderManager()->askUserToEnable();
}
#elif defined(Q_OS_LINUX)
if (added_account.isValid()) {
setAccountDisplayName(added_account);
}
#endif

#ifndef Q_OS_MAC
Expand Down Expand Up @@ -852,6 +858,26 @@ void AccountManager::setAccountSyncRoot(Account &account)
}
#endif

#if defined(Q_OS_LINUX)
void AccountManager::setAccountDisplayName(Account &account)
{
QString name = account.accountInfo.name;
if (name.isEmpty()) {
name = account.username;
}
QString displayName = name + "(" + account.serverUrl.host() + ")";
account.displayName = displayName;

QMutexLocker locker(&accounts_mutex_);
for (size_t i = 0; i < accounts_.size(); i++) {
if (accounts_.at(i) == account) {
accounts_[i].displayName = displayName;
break;
}
}
}
#endif

void AccountManager::reloginAccount(const Account &account)
{
if (account.isShibboleth) {
Expand Down
3 changes: 3 additions & 0 deletions src/account-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ private slots:
const QString getOldSyncRootDir(const Account& account);
const QString genSyncRootName(const Account& account);
void setAccountSyncRoot(Account &account);
#endif
#if defined(Q_OS_LINUX)
void setAccountDisplayName(Account &account);
#endif
static bool loadAccountsCB(struct sqlite3_stmt *stmt, void *data);
static bool loadServerInfoCB(struct sqlite3_stmt *stmt, void *data);
Expand Down
6 changes: 6 additions & 0 deletions src/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Account {
QString token;
#if defined(Q_OS_WIN32)
QString syncRoot;
#elif defined (Q_OS_LINUX)
QString displayName;
#endif
qint64 lastVisited;
bool isShibboleth;
Expand Down Expand Up @@ -68,6 +70,8 @@ class Account {
token(rhs.token),
#if defined(Q_OS_WIN32)
syncRoot(rhs.syncRoot),
#elif defined(Q_OS_LINUX)
displayName(rhs.displayName),
#endif
lastVisited(rhs.lastVisited),
isShibboleth(rhs.isShibboleth),
Expand All @@ -87,6 +91,8 @@ class Account {
token = rhs.token;
#if defined(Q_OS_WIN32)
syncRoot = rhs.syncRoot;
#elif defined(Q_OS_LINUX)
displayName = rhs.displayName;
#endif
lastVisited = rhs.lastVisited;
isShibboleth = rhs.isShibboleth;
Expand Down
15 changes: 15 additions & 0 deletions src/daemon-mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ QStringList DaemonManager::collectSeaDriveArgs()
args << sync_root_path;
#endif

#if defined(Q_OS_LINUX)
args << "-f";

QString fuse_opts = qgetenv("SEADRIVE_FUSE_OPTS");
if (fuse_opts.isEmpty()) {
QStringList umount_arguments;
umount_arguments << "-u" << gui->seadriveRoot();
QProcess::execute("fusermount", umount_arguments);
QString mount_dir = gui->seadriveRoot();
args << mount_dir;
} else {
args << fuse_opts.split(" ");
}
#endif

auto stream = qWarning() << "starting seadrive daemon:" << kSeadriveExecutable;
foreach (const QString& arg, args) {
stream << arg;
Expand Down
27 changes: 27 additions & 0 deletions src/rpc/rpc-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,33 @@ bool SeafileRpcClient::addAccount(const Account& account)

return true;
}
#elif defined(Q_OS_LINUX)
bool SeafileRpcClient::addAccount(const Account& account)
{
GError *error = NULL;
QString serverAddr = account.serverUrl.toEncoded().data();
if (serverAddr.endsWith("/")) {
serverAddr = serverAddr.left(serverAddr.size() - 1);
}

searpc_client_call__int(seadrive_rpc_client_, "seafile_add_account", &error,
6,
"string", toCStr(serverAddr),
"string", toCStr(account.username),
"string", toCStr(account.accountInfo.name),
"string", toCStr(account.token),
"string", toCStr(account.displayName),
"int", account.isPro() ? 1 : 0);
if (error) {
qWarning() << "Unable to add account" << account << ":"
<< (error->message ? error->message : "");
g_error_free(error);
return false;
}
qWarning() << "Add account" << account;

return true;
}
#endif

bool SeafileRpcClient::deleteAccount(const Account& account, bool remove_cache)
Expand Down
34 changes: 33 additions & 1 deletion src/seadrive-gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ void SeadriveGui::start()

RemoteWipeService::instance()->start();
AccountInfoService::instance()->start();
#elif defined(Q_OS_LINUX)
settings_mgr_->loadProxySettings();
settings_mgr_->applyProxySettings();

loginAccounts();

connect(daemon_mgr_, SIGNAL(daemonStarted()),
this, SLOT(onDaemonStarted()));
connect(daemon_mgr_, SIGNAL(daemonRestarted()),
this, SLOT(onDaemonRestarted()));
daemon_mgr_->startSeadriveDaemon();
#endif
}

Expand Down Expand Up @@ -543,7 +554,7 @@ void SeadriveGui::onDaemonStarted()
message_poller->start();
message_pollers_.insert(EMPTY_DOMAIN_ID, message_poller);
}
#if defined(Q_OS_WIN32)
#if defined(Q_OS_WIN32) || defined(Q_OS_LINUX)
rpc_client->connectDaemon();
#endif

Expand Down Expand Up @@ -800,6 +811,22 @@ bool SeadriveGui::initLog()
}
#endif

// On linux we must unmount the mount point dir before trying to create it,
// otherwise checkdir_with_mkdir would think it doesn't exist and try to
// create it, but the creation operation would fail.
#if defined(Q_OS_LINUX)
QStringList umount_arguments;
umount_arguments << "-u" << seadriveRoot();
QProcess::execute("fusermount", umount_arguments);
#endif

#if defined(Q_OS_LINUX)
if (checkdir_with_mkdir(toCStr(seadriveRoot())) < 0) {
errorAndExit(tr("Failed to initialize: failed to create seadrive mount folder"));
return false;
}
#endif

if (applet_log_init(toCStr(seadrive_dir.absolutePath())) < 0) {
errorAndExit(tr("Failed to initialize log: %1").arg(g_strerror(errno)));
return false;
Expand Down Expand Up @@ -1023,6 +1050,11 @@ QString SeadriveGui::seadriveRoot() const
{
return seadrive_root_;
}
#elif defined(Q_OS_LINUX)
QString SeadriveGui::seadriveRoot() const
{
return QDir::home().absoluteFilePath(getBrand());
}
#endif

QString SeadriveGui::getUniqueClientId()
Expand Down
3 changes: 2 additions & 1 deletion src/seadrive-gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SeadriveGui : public QObject {

void migrateOldConfig(const QString& data_dir);

#if defined(Q_OS_WIN32)
#if defined(Q_OS_WIN32) || defined(Q_OS_LINUX)
QString seadriveRoot() const;
#endif

Expand Down Expand Up @@ -107,6 +107,7 @@ private slots:
void onDaemonStarted();
void onDaemonRestarted();
void onDaemonRestarted(const QString& domain_id);

void connectDaemon();

private:
Expand Down
6 changes: 6 additions & 0 deletions src/ui/search-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ void SearchItemsTableView::openDirectory(bool open_file)
#endif
#ifdef Q_OS_WIN32
QString root = search_model_->account_.syncRoot;
#endif
#ifdef Q_OS_LINUX
QString root = gui->seadriveRoot();
#endif
if (root.isEmpty()) {
qWarning() << "failed to get root path";
Expand Down Expand Up @@ -561,6 +564,9 @@ void SearchItemsTableView::onItemDoubleClick(const QModelIndex& index)
#endif
#ifdef Q_OS_WIN32
QString root = search_model_->account_.syncRoot;
#endif
#ifdef Q_OS_LINUX
QString root = gui->seadriveRoot();
#endif
if (root.isEmpty()) {
qWarning() << "failed to get root path";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/transfer-progress-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ TransferItemsTableModel::TransferItemsTableModel(QObject* parent)

}

#if defined(Q_OS_WIN32)
#if defined(Q_OS_WIN32) || defined(Q_OS_LINUX)
void TransferItemsTableModel::setTransferItems()
{
TransferProgress transfer_progress;
Expand Down
6 changes: 5 additions & 1 deletion src/ui/tray-icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,14 @@ void SeafileTrayIcon::deleteAccount()
}
#endif

#ifndef Q_OS_LINUX
if (rpc_client && rpc_client->isAccountUploading(account)) {
gui->warningBox(tr("There are changes being uploaded under the account, please try again later"));
return;
}
#endif

#ifdef Q_OS_WIN32
#if defined(Q_OS_WIN32) || defined(Q_OS_LINUX)
QString question = tr("Are you sure to remove account from \"%1\"?").arg(account.serverUrl.toString());
#else
QString question = tr("Are you sure to remove account from \"%1\"? After removing account, you can still find downloaded files at ~/Library/CloudStorage.").arg(account.serverUrl.toString());
Expand All @@ -739,11 +741,13 @@ void SeafileTrayIcon::resyncAccount()
return;
}

#ifndef Q_OS_LINUX
bool is_uploading = rpc_client->isAccountUploading (account);
if (is_uploading) {
gui->warningBox (tr("There are changes being uploaded under the account, please try again later"));
return;
}
#endif

QString question = tr("The account will be synced to a new sync root folder. Are you sure to resync account from \"%1\"?").arg(account.serverUrl.toString());

Expand Down