"Fossies" - the Fresh Open Source Software Archive

Member "seafile-client-7.0.4/src/ui/account-settings-dialog.cpp" (19 Nov 2019, 3007 Bytes) of package /linux/www/seafile-client-7.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "account-settings-dialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 7.0.3_vs_7.0.4.

    1 #include <QtGui>
    2 
    3 #include "settings-mgr.h"
    4 #include "account-mgr.h"
    5 #include "seafile-applet.h"
    6 #include "rpc/rpc-client.h"
    7 #include "account-settings-dialog.h"
    8 
    9 namespace {
   10 
   11 } // namespace
   12 
   13 AccountSettingsDialog::AccountSettingsDialog(const Account& account, QWidget *parent)
   14     : QDialog(parent),
   15       account_(account)
   16 {
   17     setupUi(this);
   18     setWindowTitle(tr("Account Settings"));
   19     setWindowIcon(QIcon(":/images/seafile.png"));
   20     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
   21 
   22     mServerAddr->setText(account_.serverUrl.toString());
   23     mUsername->setText(account_.username);
   24     mUsername->setEnabled(false);
   25 
   26     #if defined(Q_OS_MAC)
   27     layout()->setContentsMargins(9, 9, 9, 9);
   28     layout()->setSpacing(6);
   29     formLayout->setSpacing(6);
   30     formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
   31     formLayout->setLabelAlignment(Qt::AlignLeft);
   32     formLayout->setFormAlignment(Qt::AlignLeft);
   33     horizontalLayout->setSpacing(6);
   34     #endif
   35 
   36     connect(mOkBtn, SIGNAL(clicked()), this, SLOT(onSubmitBtnClicked()));
   37 
   38     // const QRect screen = QApplication::desktop()->screenGeometry();
   39     // move(screen.center() - this->rect().center());
   40 }
   41 
   42 void AccountSettingsDialog::showWarning(const QString& msg)
   43 {
   44     seafApplet->warningBox(msg, this);
   45 }
   46 
   47 bool AccountSettingsDialog::validateInputs()
   48 {
   49     QString server_addr = mServerAddr->text().trimmed();
   50     QUrl url;
   51 
   52     if (server_addr.size() == 0) {
   53         showWarning(tr("Please enter the server address"));
   54         return false;
   55     } else {
   56         if (!server_addr.startsWith("http://") && !server_addr.startsWith("https://")) {
   57             showWarning(tr("%1 is not a valid server address").arg(server_addr));
   58             return false;
   59         }
   60 
   61         url = QUrl(server_addr, QUrl::StrictMode);
   62         if (!url.isValid()) {
   63             showWarning(tr("%1 is not a valid server address").arg(server_addr));
   64             return false;
   65         }
   66     }
   67 
   68     return true;
   69 }
   70 
   71 void AccountSettingsDialog::onSubmitBtnClicked()
   72 {
   73     if (!validateInputs()) {
   74         return;
   75     }
   76 
   77     QString url = mServerAddr->text().trimmed();
   78     if (url != account_.serverUrl.toString()) {
   79         Account new_account(account_);
   80         new_account.serverUrl = url;
   81         if (seafApplet->accountManager()->replaceAccount(account_,
   82             new_account) < 0) {
   83             showWarning(tr("Failed to save account information"));
   84             return;
   85         }
   86         QString error;
   87         QUrl new_server_url = new_account.serverUrl;
   88         new_server_url.setPath("/");
   89 
   90         QUrl url = account_.serverUrl;
   91         url.setPath("/");
   92 
   93         if (seafApplet->rpcClient()->updateReposServerHost(url,
   94             new_account.serverUrl.host(), new_server_url.toString(), &error) < 0) {
   95             showWarning(tr("Failed to save the changes: %1").arg(error));
   96             return;
   97         }
   98     }
   99 
  100     seafApplet->messageBox(tr("Successfully updated current account information"), this);
  101     accept();
  102 }