File: adduseraccountdialog.cpp

package info (click to toggle)
nixnote2 2.0~beta11-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,448 kB
  • ctags: 7,058
  • sloc: cpp: 68,338; java: 1,096; sh: 834; makefile: 27
file content (107 lines) | stat: -rw-r--r-- 3,625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*********************************************************************************
NixNote - An open-source client for the Evernote service.
Copyright (C) 2013 Randy Baumgarte

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
***********************************************************************************/

#include "adduseraccountdialog.h"
#include "global.h"
#include <QSpacerItem>

extern Global global;

AddUserAccountDialog::AddUserAccountDialog(QWidget *parent) :
    QDialog(parent)
{
    okPushed = false;
    okButton = new QPushButton(this);
    cancelButton = new QPushButton(this);
    buttonLayout = new QHBoxLayout();
    mainLayout = new QVBoxLayout();
    labelLayout = new QGridLayout();
    newAccountLabel = new QLabel();
    newAccountServer = new QComboBox();
    newAccountServerLabel = new QLabel();
    newAccountServerLabel->setText(tr("Server"));
    okButton->setText(tr("OK"));
    okButton->setEnabled(false);
    cancelButton->setText(tr("Cancel"));
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
    connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
    setLayout(mainLayout);

    newAccountLabel = new QLabel(tr("Account Name"));
    newAccountName = new QLineEdit();
    connect(newAccountName, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));

    labelLayout->addWidget(newAccountLabel,0,0);
    labelLayout->addWidget(newAccountName, 0, 1);
    labelLayout->addWidget(newAccountServerLabel, 1,0);;
    labelLayout->addWidget(newAccountServer,1,1);

    QSpacerItem *spacer1 = new QSpacerItem(10,10,QSizePolicy::Maximum, QSizePolicy::Minimum);
    QSpacerItem *spacer2= new QSpacerItem(10,10,QSizePolicy::Maximum, QSizePolicy::Minimum);
    buttonLayout->addSpacerItem(spacer1);
    buttonLayout->setStretch(0,100);
    buttonLayout->setStretch(3,100);
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);
    buttonLayout->addSpacerItem(spacer2);

    mainLayout->addLayout(labelLayout);
    mainLayout->addLayout(buttonLayout);

    accountNames = global.accountsManager->nameList();

    newAccountServer->addItem(tr("Evernote"), "www.evernote.com");
    newAccountServer->addItem(tr("Yinxiang Biji"), "app.yinxiang.com");
    newAccountServer->addItem(tr("Evernote Sandbox"), "sandbox.evernote.com");
    this->setFont(global.getGuiFont(font()));
}



AddUserAccountDialog::~AddUserAccountDialog() {
    delete okButton;
    delete cancelButton;
    delete buttonLayout;
    delete mainLayout;
}


void AddUserAccountDialog::cancelClicked() {
    okPushed = false;
    close();
}


void AddUserAccountDialog::okClicked() {
    okPushed = true;
    close();
}


void AddUserAccountDialog::textChanged(QString text) {
    if (text.trimmed() == "")  {
        okButton->setEnabled(false);
        return;
    }
    if (accountNames.contains(text, Qt::CaseInsensitive)) {
        okButton->setEnabled(false);
        return;
    }
    okButton->setEnabled(true);
}