OSDN Git Service

- Correct issue with importing when not a premium member.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / AccountDialog.java
1 /*\r
2  * This file is part of NixNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\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
12  *\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
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 \r
23 import java.text.SimpleDateFormat;\r
24 \r
25 import com.trolltech.qt.gui.QDialog;\r
26 import com.trolltech.qt.gui.QGridLayout;\r
27 import com.trolltech.qt.gui.QGroupBox;\r
28 import com.trolltech.qt.gui.QHBoxLayout;\r
29 import com.trolltech.qt.gui.QIcon;\r
30 import com.trolltech.qt.gui.QLabel;\r
31 import com.trolltech.qt.gui.QPushButton;\r
32 \r
33 import cx.fbn.nevernote.Global;\r
34 \r
35 public class AccountDialog extends QDialog {\r
36     String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
37         private final QPushButton ok;\r
38         \r
39         // Constructor\r
40         public AccountDialog() {\r
41                 \r
42                 // Setup window layout, title, & icon\r
43                 setWindowTitle(tr("Account Information"));\r
44                 setWindowIcon(new QIcon(new QIcon(iconPath+"account.png")));\r
45                 QGridLayout grid = new QGridLayout();\r
46                 setLayout(grid);\r
47                 QLabel premium;\r
48                 if (Global.isPremium())\r
49                         premium = new QLabel(tr("Premium"));\r
50                 else\r
51                         premium = new QLabel(tr("Free"));\r
52                 \r
53                 String userName = Global.username;\r
54                 \r
55                 // calculate the upload amount\r
56                 Long uploadAmt = Global.getUploadAmount();\r
57                 Long uploadLimit = Global.getUploadLimit();\r
58                 Long uploadLimitEnd = Global.getUploadLimitEnd();\r
59                 Long pct;\r
60                 if (uploadLimit > 0)\r
61                         pct = uploadAmt*100 / uploadLimit;\r
62                 else\r
63                         pct = new Long(0);\r
64                 String unit = tr(" Bytes");\r
65                 \r
66                 if (uploadAmt > 0) {\r
67                         uploadAmt = uploadAmt/1024;\r
68                         unit = tr(" KB");\r
69                 }\r
70                 if (uploadAmt >= 1024) {\r
71                         uploadAmt = uploadAmt / 1024;\r
72                         unit = tr(" MB");\r
73                 }\r
74                 if (uploadLimit > 0)\r
75                         uploadLimit = uploadLimit/1024/1024;\r
76         \r
77                 //showing only date need\r
78                 String fmt = Global.getDateFormat() /* + " " + Global.getTimeFormat()*/;\r
79                 String dateTimeFormat = new String(fmt);\r
80                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
81                 StringBuilder endDate = new StringBuilder(simple.format(uploadLimitEnd));\r
82                 \r
83                 // Show limits\r
84                 QGroupBox limitGroup = new QGroupBox(tr("Account:"));\r
85 \r
86                 QGridLayout textGrid = new QGridLayout();\r
87                 textGrid.addWidget(new QLabel(tr("User Name:")),1,1);\r
88                 textGrid.addWidget(new QLabel(userName), 1,2);\r
89                 textGrid.addWidget(new QLabel(tr("Account Type:")), 2,1);\r
90                 textGrid.addWidget(premium, 2, 2);\r
91                 textGrid.addWidget(new QLabel(tr("Limit:")), 3,1);\r
92                 textGrid.addWidget(new QLabel(uploadLimit.toString() +" MB"),3,2);\r
93                 textGrid.addWidget(new QLabel(tr("Uploaded In This Period:")), 4,1);\r
94                 if (uploadAmt > 0)\r
95                         textGrid.addWidget(new QLabel(uploadAmt.toString()+unit +" ("+pct+"%)"),4,2);\r
96                 else\r
97                         textGrid.addWidget(new QLabel(tr("Less than 1MB")),4,2);\r
98                 textGrid.addWidget(new QLabel(tr("Current Cycle Ends:")), 5,1);\r
99                 textGrid.addWidget(new QLabel(endDate.toString()),5,2);\r
100                 limitGroup.setLayout(textGrid);\r
101 \r
102                 grid.addWidget(limitGroup, 1, 1);\r
103 \r
104                 //UserAttributes attrib = Global.getUserAttributes();\r
105                 //QGridLayout attribGrid = new QGridLayout();\r
106                 //QGroupBox attribGroup = new QGroupBox(tr("User Attributes"));\r
107                 //attribGrid.addWidget(new QLabel(tr("Incoming Email:")), 1,1);\r
108                 //String server = Global.getServer();\r
109                 //if (server.startsWith("www."))\r
110                         //server = server.substring(4);\r
111                 \r
112                 //usually evernote mail is user@m.evernote.com\r
113                 //server = "m."+server;\r
114                 \r
115                 //attribGrid.addWidget(createIncomingEmailField(attrib.getIncomingEmailAddress()+"@"+server), 1,2);\r
116                 //attribGroup.setLayout(attribGrid);\r
117                 //grid.addWidget(attribGroup, 2,1);\r
118 \r
119                 \r
120                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
121                 ok = new QPushButton("OK");\r
122                 ok.clicked.connect(this, "okPushed()");\r
123                 buttonLayout.addStretch();\r
124                 buttonLayout.addWidget(ok);\r
125                 buttonLayout.addStretch();\r
126                 grid.addLayout(buttonLayout,3,1);\r
127         }\r
128         \r
129         // build a field used for the incomming email\r
130         /*\r
131         private QWidget createIncomingEmailField(String email){\r
132                 QTextEdit emailTextEdit = new QTextEdit();\r
133                 \r
134                 String emailLinkFormat="<a href=\"mailto:%1$s\">%1$s</a>";\r
135                 String emailHtml = String.format(emailLinkFormat, email);\r
136                 \r
137                 emailTextEdit.setLineWrapMode(LineWrapMode.NoWrap);\r
138 \r
139                 QTextDocument doc = new QTextDocument();\r
140                 doc.setHtml(emailHtml);\r
141                 doc.setMaximumBlockCount(1);\r
142                 \r
143                 emailTextEdit.setDocument(doc);\r
144                 emailTextEdit.setReadOnly(true);\r
145 \r
146                 //set background color as for disabled control \r
147                 QPalette palette = new QPalette();\r
148                 QColor backgroundColor = QApplication.palette().color(ColorRole.Window);\r
149                 palette.setColor(ColorRole.Base, backgroundColor);\r
150                 \r
151                 emailTextEdit.setAutoFillBackground(true);\r
152                 emailTextEdit.setPalette(palette);\r
153                 \r
154                 //remove frame borders\r
155                 emailTextEdit.setFrameShape(QFrame.Shape.NoFrame);\r
156                 \r
157                 //set height of emailTextEdit actually single line\r
158                 QFontMetrics fontMetrics = emailTextEdit.fontMetrics();\r
159                 //we also add some pixels to avoid showing scrollbars\r
160                 int height = fontMetrics.height() + emailTextEdit.frameWidth()*2 + 8;\r
161                 emailTextEdit.setFixedHeight(height);\r
162                 \r
163                 return emailTextEdit;\r
164         }\r
165         */\r
166         \r
167         // OK button pushed, close the window\r
168         @SuppressWarnings("unused")\r
169         private void okPushed() {\r
170                 this.close();\r
171         }\r
172         \r
173         // return the actual OK button\r
174         public QPushButton getOkButton() {\r
175                 return ok;\r
176         }\r
177 }\r