1 | /* |
---|
2 | * BCGateway.cpp |
---|
3 | * |
---|
4 | * Created on: Jul 9, 2009 |
---|
5 | * Author: saemy |
---|
6 | */ |
---|
7 | |
---|
8 | #include "BCGateway.h" |
---|
9 | |
---|
10 | #include "BCAccount.h" |
---|
11 | #include "../ui/vcsettingswidget.h" |
---|
12 | |
---|
13 | namespace SwisscomXtraZone { |
---|
14 | |
---|
15 | ILoginGateway* BCGateway::instance_ = NULL; |
---|
16 | ILoginGateway* BCGateway::instance(){ |
---|
17 | return instance_ ? instance_ : (instance_ = new BCGateway); |
---|
18 | } |
---|
19 | |
---|
20 | |
---|
21 | QString BCGateway::name() const { |
---|
22 | return "SwisscomXtraZone"; |
---|
23 | } |
---|
24 | |
---|
25 | QImage BCGateway::icon() const { |
---|
26 | return QImage(":/images/SwisscomXtraZone.ico"); |
---|
27 | } |
---|
28 | |
---|
29 | QSet<int> BCGateway::validRecipientCountryCodes() const { |
---|
30 | QSet<int> result; |
---|
31 | result.insert(41); // CH |
---|
32 | return result; |
---|
33 | } |
---|
34 | |
---|
35 | IAccount* BCGateway::createAccountInstance(IStorage* storage) const { |
---|
36 | return new BCAccount(storage); |
---|
37 | } |
---|
38 | |
---|
39 | IAccountSettingsWidget* BCGateway::getAccountSettingsWidget(QWidget* parent /* = 0 */) const { |
---|
40 | return new VCSettingsWidget(parent); |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | QString BCGateway::addonText() const { |
---|
46 | return addonText_; |
---|
47 | } |
---|
48 | void BCGateway::setAddonText(const QString& addonText) { |
---|
49 | addonText_ = addonText; |
---|
50 | } |
---|
51 | |
---|
52 | int BCGateway::longSMSLength() const { |
---|
53 | return longSMSLength_; |
---|
54 | } |
---|
55 | void BCGateway::setLongSMSLength(int longSMSLength) { |
---|
56 | longSMSLength_ = longSMSLength; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | /** |
---|
62 | * Splits the given text into a list of long-sms. <br/> |
---|
63 | * Since the long-sms-length is synchronized with the gateway, this list is as it will be splitted while sending. |
---|
64 | * |
---|
65 | * @param QString text The text which should be splitted |
---|
66 | * @return Returns a list of the long-sms texts |
---|
67 | */ |
---|
68 | QList<QString> BCGateway::splitTextToLongSMS(const QString& text) const { |
---|
69 | QList<QString> longSMSList; |
---|
70 | QString text_(text); |
---|
71 | |
---|
72 | int longSMSLengthWOAddonText = longSMSLength_ - addonText_.length(); |
---|
73 | while (text_ != "") { |
---|
74 | longSMSList.append(text_.left(longSMSLengthWOAddonText)); |
---|
75 | text_.remove(0, longSMSLengthWOAddonText); |
---|
76 | } |
---|
77 | |
---|
78 | return longSMSList; |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * Splits the given text into a list of short-sms. <br/> |
---|
83 | * This is only a hypotetic list, since the short-sms-count could vary and it that is not checked anywhere in here. |
---|
84 | * The SHORTSMS_LENGTH is a static value.<br/> |
---|
85 | * However, since the splitTextToLongSMS is the real value (that size is synchronized with the web page) the, short-sms size is |
---|
86 | * not totally wrong. |
---|
87 | * |
---|
88 | * @param QString text The text which should be splitted. |
---|
89 | * @return Returns a list of the short-sms texts |
---|
90 | */ |
---|
91 | QList<QString> BCGateway::splitTextToShortSMS(const QString& text) const { |
---|
92 | QList<QString> shortSMSList; |
---|
93 | |
---|
94 | QList<QString> longSMSList = splitTextToLongSMS(text); |
---|
95 | |
---|
96 | QListIterator<QString> i(longSMSList); |
---|
97 | while (i.hasNext()){ |
---|
98 | QString subText = i.next() + addonText_; |
---|
99 | while (subText != "") { |
---|
100 | shortSMSList.append(subText.left(SHORTSMS_LENGTH)); |
---|
101 | subText.remove(0, SHORTSMS_LENGTH); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | return shortSMSList; |
---|
106 | } |
---|
107 | |
---|
108 | } |
---|