2 * This file is part of NixNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.dialog;
\r
23 import java.text.SimpleDateFormat;
\r
25 import com.evernote.edam.type.UserAttributes;
\r
26 import com.trolltech.qt.gui.QApplication;
\r
27 import com.trolltech.qt.gui.QColor;
\r
28 import com.trolltech.qt.gui.QDialog;
\r
29 import com.trolltech.qt.gui.QFontMetrics;
\r
30 import com.trolltech.qt.gui.QFrame;
\r
31 import com.trolltech.qt.gui.QGridLayout;
\r
32 import com.trolltech.qt.gui.QGroupBox;
\r
33 import com.trolltech.qt.gui.QHBoxLayout;
\r
34 import com.trolltech.qt.gui.QIcon;
\r
35 import com.trolltech.qt.gui.QLabel;
\r
36 import com.trolltech.qt.gui.QPalette;
\r
37 import com.trolltech.qt.gui.QPalette.ColorRole;
\r
38 import com.trolltech.qt.gui.QPushButton;
\r
39 import com.trolltech.qt.gui.QTextDocument;
\r
40 import com.trolltech.qt.gui.QTextEdit;
\r
41 import com.trolltech.qt.gui.QTextEdit.LineWrapMode;
\r
42 import com.trolltech.qt.gui.QWidget;
\r
44 import cx.fbn.nevernote.Global;
\r
46 public class AccountDialog extends QDialog {
\r
47 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
48 private final QPushButton ok;
\r
51 public AccountDialog() {
\r
53 // Setup window layout, title, & icon
\r
54 setWindowTitle(tr("Account Information"));
\r
55 setWindowIcon(new QIcon(new QIcon(iconPath+"account.png")));
\r
56 QGridLayout grid = new QGridLayout();
\r
59 if (Global.isPremium())
\r
60 premium = new QLabel(tr("Premium"));
\r
62 premium = new QLabel(tr("Free"));
\r
64 String userName = Global.username;
\r
66 // calculate the upload amount
\r
67 Long uploadAmt = Global.getUploadAmount();
\r
68 Long uploadLimit = Global.getUploadLimit();
\r
69 Long uploadLimitEnd = Global.getUploadLimitEnd();
\r
71 if (uploadLimit > 0)
\r
72 pct = uploadAmt*100 / uploadLimit;
\r
75 String unit = tr(" Bytes");
\r
77 if (uploadAmt > 0) {
\r
78 uploadAmt = uploadAmt/1024;
\r
81 if (uploadAmt >= 1024) {
\r
82 uploadAmt = uploadAmt / 1024;
\r
85 if (uploadLimit > 0)
\r
86 uploadLimit = uploadLimit/1024/1024;
\r
88 //showing only date need
\r
89 String fmt = Global.getDateFormat() /* + " " + Global.getTimeFormat()*/;
\r
90 String dateTimeFormat = new String(fmt);
\r
91 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);
\r
92 StringBuilder endDate = new StringBuilder(simple.format(uploadLimitEnd));
\r
95 QGroupBox limitGroup = new QGroupBox(tr("Account:"));
\r
97 QGridLayout textGrid = new QGridLayout();
\r
98 textGrid.addWidget(new QLabel(tr("User Name:")),1,1);
\r
99 textGrid.addWidget(new QLabel(userName), 1,2);
\r
100 textGrid.addWidget(new QLabel(tr("Account Type:")), 2,1);
\r
101 textGrid.addWidget(premium, 2, 2);
\r
102 textGrid.addWidget(new QLabel(tr("Limit:")), 3,1);
\r
103 textGrid.addWidget(new QLabel(uploadLimit.toString() +" MB"),3,2);
\r
104 textGrid.addWidget(new QLabel(tr("Uploaded In This Period:")), 4,1);
\r
105 textGrid.addWidget(new QLabel(uploadAmt.toString()+unit +" ("+pct+"%)"),4,2);
\r
106 textGrid.addWidget(new QLabel(tr("Current Cycle Ends:")), 5,1);
\r
107 textGrid.addWidget(new QLabel(endDate.toString()),5,2);
\r
108 limitGroup.setLayout(textGrid);
\r
110 grid.addWidget(limitGroup, 1, 1);
\r
112 UserAttributes attrib = Global.getUserAttributes();
\r
113 QGridLayout attribGrid = new QGridLayout();
\r
114 QGroupBox attribGroup = new QGroupBox(tr("User Attributes"));
\r
115 attribGrid.addWidget(new QLabel(tr("Incoming Email:")), 1,1);
\r
116 String server = Global.getServer();
\r
117 if (server.startsWith("www."))
\r
118 server = server.substring(4);
\r
120 //usually evernote mail is user@m.evernote.com
\r
121 server = "m."+server;
\r
123 attribGrid.addWidget(createIncomingEmailField(attrib.getIncomingEmailAddress()+"@"+server), 1,2);
\r
124 attribGroup.setLayout(attribGrid);
\r
125 grid.addWidget(attribGroup, 2,1);
\r
128 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
129 ok = new QPushButton("OK");
\r
130 ok.clicked.connect(this, "okPushed()");
\r
131 buttonLayout.addStretch();
\r
132 buttonLayout.addWidget(ok);
\r
133 buttonLayout.addStretch();
\r
134 grid.addLayout(buttonLayout,3,1);
\r
137 // build a field used for the incomming email
\r
138 private QWidget createIncomingEmailField(String email){
\r
139 QTextEdit emailTextEdit = new QTextEdit();
\r
141 String emailLinkFormat="<a href=\"mailto:%1$s\">%1$s</a>";
\r
142 String emailHtml = String.format(emailLinkFormat, email);
\r
144 emailTextEdit.setLineWrapMode(LineWrapMode.NoWrap);
\r
146 QTextDocument doc = new QTextDocument();
\r
147 doc.setHtml(emailHtml);
\r
148 doc.setMaximumBlockCount(1);
\r
150 emailTextEdit.setDocument(doc);
\r
151 emailTextEdit.setReadOnly(true);
\r
153 //set background color as for disabled control
\r
154 QPalette palette = new QPalette();
\r
155 QColor backgroundColor = QApplication.palette().color(ColorRole.Window);
\r
156 palette.setColor(ColorRole.Base, backgroundColor);
\r
158 emailTextEdit.setAutoFillBackground(true);
\r
159 emailTextEdit.setPalette(palette);
\r
161 //remove frame borders
\r
162 emailTextEdit.setFrameShape(QFrame.Shape.NoFrame);
\r
164 //set height of emailTextEdit actually single line
\r
165 QFontMetrics fontMetrics = emailTextEdit.fontMetrics();
\r
166 //we also add some pixels to avoid showing scrollbars
\r
167 int height = fontMetrics.height() + emailTextEdit.frameWidth()*2 + 8;
\r
168 emailTextEdit.setFixedHeight(height);
\r
170 return emailTextEdit;
\r
173 // OK button pushed, close the window
\r
174 @SuppressWarnings("unused")
\r
175 private void okPushed() {
\r
179 // return the actual OK button
\r
180 public QPushButton getOkButton() {
\r