Changeset 56:e63ceb8090cd in SMSSender
- Timestamp:
- Feb 2, 2010 9:53:45 AM (8 years ago)
- Branch:
- 3.0
- Convert:
- svn:3639001d-8e34-449c-bb86-3782b86c4877/branches/3.0@55
- Files:
-
- 18 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
gateways/SwisscomXtraZone/src/business/BCGateway.cpp
r43 r56 25 25 QImage BCGateway::icon() const { 26 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; 27 33 } 28 34 -
gateways/SwisscomXtraZone/src/business/BCGateway.h
r43 r56 26 26 27 27 /* IGateway */ 28 virtual QString name() const; 29 virtual QImage icon() const; 28 QString name() const; 29 QImage icon() const; 30 QSet<int> validRecipientCountryCodes() const; 30 31 31 virtualIAccount* createAccountInstance(IStorage* storage) const;32 IAccount* createAccountInstance(IStorage* storage) const; 32 33 33 virtualQList<QString> splitTextToLongSMS(const QString& text) const;34 virtualQList<QString> splitTextToShortSMS(const QString& text) const;34 QList<QString> splitTextToLongSMS(const QString& text) const; 35 QList<QString> splitTextToShortSMS(const QString& text) const; 35 36 36 virtualIAccountSettingsWidget* getAccountSettingsWidget(QWidget* parent = 0) const;37 IAccountSettingsWidget* getAccountSettingsWidget(QWidget* parent = 0) const; 37 38 38 39 39 virtualQString addonText() const;40 v irtual void setAddonText(const QString& addonText);40 QString addonText() const; 41 void setAddonText(const QString& addonText); 41 42 42 virtualint longSMSLength() const;43 v irtual void setLongSMSLength(int longSMSLength);43 int longSMSLength() const; 44 void setLongSMSLength(int longSMSLength); 44 45 45 46 protected: -
lib/libdatatypes/src/business/BCContact.cpp
r55 r56 66 66 void BCContact::setImage(const QImage& image){ 67 67 SET_IF_DIFFERENT(image_, image); 68 image_ = image_.scaledToWidth(50, Qt::SmoothTransformation); 68 69 emit contactEvents()->dataChanged(); 69 70 } -
lib/libdatatypes/src/snumber.cpp
r43 r56 25 25 * aa area code (2-digits) 26 26 * aaa area code (3-digits) 27 *28 27 * AAA area code trim zeros 29 28 * … … 34 33 const QString SNumber::IsoFormat = "'+'cc' 'aaa' 'u"; // +41 079 1234567 35 34 const QString SNumber::IsoFormatShort = "'+'CC' 'AAA' 'u"; // +41 79 1234567 35 const QString SNumber::GuessFormat = "%%guess%%"; 36 36 37 37 SNumber::SNumber() { 38 38 clear(); 39 39 } 40 SNumber::SNumber(const QString& numberStr, const QString& format /* = SNumber::IsoFormat */) {40 SNumber::SNumber(const QString& numberStr, const QString& format) { 41 41 setNumber(numberStr, format); 42 42 } … … 72 72 73 73 /* CC & AAA are not applicable here! */ 74 bool SNumber::setNumber(const QString& numberStr, const QString& format /* = SNumber::IsoFormat */){ 74 bool SNumber::setNumber(const QString& numberStr, const QString& format){ 75 if (format == SNumber::GuessFormat) { 76 QStringList formats; 77 formats.append("'+'cc' 'aaa' 'u");// +41 079 1234567 78 formats.append("'+'cc' 'aa' 'u"); // +41 79 1234567 79 formats.append("'+'cc' 'a' 'u"); // +41 7 1234567 80 formats.append("'+'c' 'aaa' 'u"); // +1 079 1234567 81 formats.append("'+'c' 'aa' 'u"); // +1 79 1234567 82 formats.append("'+'c' 'a' 'u"); // +1 7 1234567 83 formats.append("'+'cc' 'aaau"); // +41 0791234567 (Attention! A part of the usernumber could be interpreted as the areacode) 84 formats.append("'+'cc' 'aau"); // +41 791234567 (Attention! A part of the usernumber could be interpreted as the areacode) 85 formats.append("'+'cc' 'au"); // +41 71234567 (Attention! A part of the usernumber could be interpreted as the areacode) 86 formats.append("'+'c' 'aaau"); // +1 0791234567 (Attention! A part of the usernumber could be interpreted as the areacode) 87 formats.append("'+'c' 'aau"); // +1 791234567 (Attention! A part of the usernumber could be interpreted as the areacode) 88 formats.append("'+'c' 'au"); // +1 71234567 (Attention! A part of the usernumber could be interpreted as the areacode) 89 90 foreach(QString format_, formats) { 91 if (setNumber(numberStr, format_)) { 92 return true; 93 } 94 } 95 return false; 96 } 97 75 98 clear(); 76 99 77 qDebug() << numberStr; 78 qDebug() << format; 100 qDebug() << "Checking " + format + " on " + numberStr; 79 101 80 102 const QLatin1Char quote('\''); … … 85 107 int j = 0; 86 108 for (int i = 0; i < format.count(); i++) { 109 if (numberStr.count() <= j) { 110 clear(); 111 break; 112 } 113 87 114 if (format.at(i) == quote) { 88 115 inQuote = !inQuote; … … 129 156 j++; 130 157 } else { 158 if (format.mid(i, 2) == "CC") { 159 qWarning() << "CC not supported here!"; 160 } else if (format.mid(i, 3) == "AAA") { 161 qWarning() << "AAA not supported here!"; 162 } 131 163 clear(); 132 164 break; … … 168 200 } 169 201 170 QString SNumber::toString(const QString& format /* = SNumber::IsoFormat */) const {202 QString SNumber::toString(const QString& format) const { 171 203 if (!isValid()) { 172 204 return ""; … … 219 251 } 220 252 221 void SNumber::fromString(const QString& string, const QString& format /* = SNumber::IsoFormat */) { 222 setNumber(string, format); 253 bool SNumber::readFromString(const QString& string, const QString& format) { 254 return setNumber(string, format); 255 } 256 SNumber SNumber::fromString(const QString& string, const QString& format) { 257 return SNumber(string, format); 223 258 } 224 259 -
lib/libdatatypes/src/snumber.h
r43 r56 17 17 static const QString IsoFormat; 18 18 static const QString IsoFormatShort; 19 static const QString GuessFormat; 19 20 20 21 public: … … 34 35 35 36 QString toString(const QString& format = SNumber::IsoFormat) const; 36 void fromString(const QString& string, const QString& format = SNumber::IsoFormat);37 bool readFromString(const QString& string, const QString& format = SNumber::IsoFormat); 37 38 38 39 bool operator==(const SNumber& n) const; 39 40 inline bool operator!=(const SNumber& n) const { return !(*this == n); } 40 41 42 static SNumber fromString(const QString& string, const QString& format = SNumber::IsoFormat); 41 43 protected: 42 44 void setCountryCode(short countryCode); -
lib/libinterfaces/src/business/igateway.h
r43 r56 12 12 #include <QString> 13 13 #include <QList> 14 #include <QSet> 14 15 #include <QWidget> 15 16 #include <QImage> … … 28 29 virtual QString name() const =0; 29 30 virtual QImage icon() const =0; 31 virtual QSet<int> validRecipientCountryCodes() const =0; 30 32 31 33 virtual IAccount* createAccountInstance() const =0; … … 34 36 virtual IStorage* defaultStorage() const =0; 35 37 virtual void setDefaultStorage(IStorage* storage) =0; 36 37 38 38 39 virtual QList<QString> splitTextToLongSMS(const QString& text) const =0; -
smssender.pro
r55 r56 21 21 lib/libutils/src \ 22 22 include 23 HEADERS += src/ui/models/grouptablemodel.h \ 23 HEADERS += src/ui/models/accounttreemodel.h \ 24 src/ui/models/loadedaccountmodel.h \ 25 src/ui/models/grouptablemodel.h \ 24 26 src/ui/models/contacttablemodel.h \ 25 27 src/persistence/storage/DAAccountListManager.h \ … … 28 30 src/ui/models/aliascompletionmodel.h \ 29 31 src/ui/completers/bettercompleter.h \ 30 src/ui/models/accountmodel.h \31 32 src/ui/delegates/aligndelegate.h \ 32 33 src/ui/components/clearbutton.h \ … … 57 58 src/ui/VCMain/vcmain.h \ 58 59 src/ui/VCSettings/vcsettings.h 59 SOURCES += src/ui/models/grouptablemodel.cpp \ 60 SOURCES += src/ui/models/accounttreemodel.cpp \ 61 src/ui/models/loadedaccountmodel.cpp \ 62 src/ui/models/grouptablemodel.cpp \ 60 63 src/ui/models/contacttablemodel.cpp \ 61 64 src/persistence/storage/DAAccountListManager.cpp \ … … 64 67 src/ui/models/aliascompletionmodel.cpp \ 65 68 src/ui/completers/bettercompleter.cpp \ 66 src/ui/models/accountmodel.cpp \67 69 src/ui/delegates/aligndelegate.cpp \ 68 70 src/ui/components/clearbutton.cpp \ -
src/business/BCContactManager.cpp
r43 r56 59 59 } 60 60 61 IContact* BCContactManager::getContact(int contactId) {61 IContact* BCContactManager::getContact(int contactId) const { 62 62 return contactList_.value(contactId); 63 63 } 64 64 65 QSet<IContact*> BCContactManager::getContactList() {65 QSet<IContact*> BCContactManager::getContactList() const { 66 66 return contactList_.values().toSet(); 67 67 } … … 83 83 } 84 84 85 IContact* BCContactManager::getContactByNumber(const SNumber number) const { 86 foreach (IContact* contact, getContactList()) { 87 if (number == contact->number()) { 88 return contact; 89 } 90 } 91 return NULL; 92 } 93 94 85 95 void BCContactManager::contactIdChanged(int oldId, int newId) { 86 96 IContact* contact = contactList_.take(oldId); -
src/business/BCContactManager.h
r43 r56 6 6 */ 7 7 8 #ifndef CONTACTMANAGER_H_9 #define CONTACTMANAGER_H_8 #ifndef BC_CONTACTMANAGER_H_ 9 #define BC_CONTACTMANAGER_H_ 10 10 11 11 #include <QObject> … … 14 14 15 15 #include <icontact.h> 16 #include <snumber.h> 16 17 17 18 class BCContactManager: public QObject { … … 21 22 static BCContactManager* instance(); 22 23 23 virtual IContact* getContact(int contactId); 24 virtual QSet<IContact*> getContactList(); 25 virtual void saveContact(IContact* contact); 26 virtual void removeContact(int contactId); 24 IContact* getContact(int contactId) const; 25 QSet<IContact*> getContactList() const; 26 void saveContact(IContact* contact); 27 void removeContact(int contactId); 28 29 IContact* getContactByNumber(const SNumber number) const; 27 30 28 31 signals: 29 void 30 void 31 void 32 void contactAdded(IContact* contact); 33 void contactUpdated(IContact* contact); 34 void contactRemoved(IContact* contact); 32 35 33 36 protected: … … 35 38 virtual ~BCContactManager(){}; 36 39 37 virtual void 40 virtual void readContactsFromStorage(); 38 41 39 42 protected slots: 40 void 41 void 43 void contactIdChanged(int oldId, int newId); 44 void contactDataChanged(); 42 45 43 46 private: -
src/business/BCSettings.cpp
r43 r56 10 10 #include <QDirIterator> 11 11 #include <QFileInfo> 12 #include <QCoreApplication> 13 #include <QDesktopServices> 12 14 13 15 #include "../persistence/PersistenceFactory.h" … … 24 26 } 25 27 28 QString BCSettings::getSettingsPath(){ 29 if (QFile::exists(qApp->applicationDirPath() + "/data.db")) { 30 return qApp->applicationDirPath() + "/"; 31 } else { 32 return QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/gorrion/SMSSender/"; 33 } 34 } 26 35 27 36 const QString BCSettings::getLocalePath(){ 28 return "locale/";37 return qApp->applicationDirPath() + "/locale/"; 29 38 } 30 39 … … 117 126 118 127 119 QString BCSettings::getSettingsPath(){120 return "./";121 }122 123 124 128 void BCSettings::setLocale(const QLocale& locale){ 125 129 return getSettings()->setLocale(locale); -
src/ui/VCAccountList/vcaccountlist.cpp
r55 r56 22 22 ui.setupUi(this); 23 23 24 model_ = new Account Model(this);24 model_ = new AccountTreeModel(this); 25 25 proxyModel_ = new BetterCompletionModel(this); 26 26 proxyModel_->setFilterKeyColumn(-1); … … 32 32 ui.tblViewAccounts->resizeRowsToContents(); 33 33 ui.tblViewAccounts->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); 34 ui.tblViewAccounts->horizontalHeader()->setResizeMode(Account Model::ColName, QHeaderView::Stretch);35 ui.tblViewAccounts->sortByColumn(Account Model::ColName, Qt::AscendingOrder);34 ui.tblViewAccounts->horizontalHeader()->setResizeMode(AccountTreeModel::ColName, QHeaderView::Stretch); 35 ui.tblViewAccounts->sortByColumn(AccountTreeModel::ColName, Qt::AscendingOrder); 36 36 ui.tblViewAccounts->resizeColumnsToContents(); 37 37 ui.tblViewAccounts->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); -
src/ui/VCAccountList/vcaccountlist.h
r55 r56 11 11 #include <iaccount.h> 12 12 13 #include "../models/account model.h"13 #include "../models/accounttreemodel.h" 14 14 15 15 class VCAccountList: public QDialog { … … 23 23 Ui::VCAccountListClass ui; 24 24 25 Account Model*model_;25 AccountTreeModel* model_; 26 26 QSortFilterProxyModel* proxyModel_; 27 27 -
src/ui/VCAddressBook/vcaddressbook.ui
r55 r56 199 199 <size> 200 200 <width>50</width> 201 <height> 64</height>201 <height>0</height> 202 202 </size> 203 203 </property> -
src/ui/VCEditContact/vceditcontact.cpp
r43 r56 6 6 #include <QtGui/QFileDialog> 7 7 #include <QtGui/QMessageBox> 8 8 #include <QDebug> 9 9 #include <QStringList> 10 #include <QSortFilterProxyModel> 10 11 11 12 #include "../UIHelper.h" … … 25 26 26 27 ui.edtName->setText(contact->name()); 27 ui.edtNumber->setText(contact->number().toString(SNumber::IsoFormatShort)); 28 if (!contact->number().isValid()) { 29 ui.edtCountryCode->setText("+41"); 30 ui.edtNumber->setText(""); 31 } else { 32 ui.edtCountryCode->setText(contact->number().toString("'+'CC")); 33 ui.edtNumber->setText(contact->number().toString("AAA' 'u")); 34 } 28 35 29 36 // Load aliases 30 QStringList aliases = contact->aliases(); 31 for (int x = 0; x < aliases.size(); ++x){ 32 QString alias = aliases.at(x); 33 ui.lstAliases->addItem(alias); 34 } 35 ui.lstAliases->sortItems(); 37 foreach (QString alias, contact->aliases()) { 38 addAliasItem(alias); 39 } 40 QSortFilterProxyModel* model = new QSortFilterProxyModel(this); 41 model->setSourceModel(ui.lstAliases->model()); 42 model->setDynamicSortFilter(true); 43 model->setSortCaseSensitivity(Qt::CaseInsensitive); 44 model->sort(0, Qt::AscendingOrder); 45 // ui.lstAliases->sortItems(); 36 46 37 47 setIcon(contact->image()); … … 40 50 // First "signal" to initialize some slots 41 51 on_lstAliases_itemSelectionChanged(); 52 } 53 VCEditContact::~VCEditContact() { 54 42 55 } 43 56 … … 118 131 // Aliases 119 132 120 QString VCEditContact::editAlias(const QString& alias){ 133 QListWidgetItem* VCEditContact::addAliasItem(const QString& alias) { 134 QListWidgetItem* item = new QListWidgetItem(alias); 135 item->setFlags(item->flags() | Qt::ItemIsEditable); 136 ui.lstAliases->addItem(item); 137 } 138 /* 139 void VCEditContact::editAlias(const QString& alias){ 121 140 bool ok; 122 QString text= QInputDialog::getText(this, tr("SMSSender"),141 QString newAlias = QInputDialog::getText(this, tr("SMSSender"), 123 142 tr("Enter an alias for that contact:"), 124 143 QLineEdit::Normal, 125 144 alias, &ok); 126 145 if (ok){ 127 text = text.trimmed(); 146 if ((alias != "") && (newAlias.trimmed() == "")){ 147 if (QMessageBox::Yes == QMessageBox::information(this, tr("SMSSender"), 148 tr("You entered a empty value. Do you want to delete this alias?"), 149 QMessageBox::Yes, 150 QMessageBox::No | QMessageBox::Default | QMessageBox::Escape)) { 151 foreach (QListWidgetItem* item, ui.lstAliases->findItems(alias, Qt::MatchFixedString)) { 152 ui.lstAliases->takeItem(ui.lstAliases->indexFromItem(item)->row()); 153 } 154 } 155 } 156 157 if (ui.lstAliases->findItems(alias, Qt::MatchFixedString).count() > 0){ // Is it already in the list? 158 QMessageBox::information(this, tr("SMSSender"), 159 tr("This contact is already known under this alias."), 160 QMessageBox::Ok | QMessageBox::Default | QMessageBox::Escape); 161 } 162 163 newAliases = newAlias.split(","); 164 foreach (QString newAlias, newAliases) { 165 newAlias = newAlias.trimmed(); 166 167 if (ui.lstAliases->findItems(alias, Qt::MatchFixedString).count() == 0){ // Is it already in the list? 168 ui.lstAliases->insertItem(ui.lstAliases->count(), alias); 169 } 170 } 171 172 173 128 174 return text; 129 175 }else{ 130 176 return alias; 131 177 } 132 } 178 }*/ 133 179 134 180 void VCEditContact::on_lstAliases_itemSelectionChanged(){ 135 181 ui.btnRemoveAlias->setEnabled(ui.lstAliases->selectedItems().count() > 0); 182 ui.btnEditAlias->setEnabled(ui.lstAliases->selectedItems().count() > 0); 136 183 } 137 184 138 185 void VCEditContact::on_btnAddAlias_clicked(){ 139 QString alias = editAlias(QString()); 140 141 if (alias != ""){ // If empty, then do not add it 142 if (ui.lstAliases->findItems(alias, Qt::MatchFixedString).count() == 0){ // Is it already in the list? 143 ui.lstAliases->insertItem(ui.lstAliases->count(), alias); 144 }else{ 145 QMessageBox::information(this, tr("SMSSender"), 146 tr("This contact is already known under this alias."), 147 QMessageBox::Ok | QMessageBox::Default | QMessageBox::Escape); 148 } 149 } 150 } 151 152 void VCEditContact::on_lstAliases_itemDoubleClicked(QListWidgetItem* item){ 186 QList<QListWidgetItem*> emptyItems = ui.lstAliases->findItems("", Qt::MatchFixedString); 187 if (emptyItems.isEmpty()) { 188 emptyItems.append(addAliasItem("")); 189 } 190 ui.lstAliases->setFocus(); 191 emptyItems.first()->setSelected(true); 192 on_btnEditAlias_clicked(); 193 } 194 void VCEditContact::on_btnEditAlias_clicked() { 195 QList<QListWidgetItem*> selectedItems = ui.lstAliases->selectedItems(); 196 if (!selectedItems.isEmpty()) { 197 ui.lstAliases->setFocus(); 198 ui.lstAliases->editItem(selectedItems.first()); 199 } 200 } 201 202 203 void VCEditContact::on_lstAliases_itemChanged(QListWidgetItem* item) { 204 QString alias = item->text().trimmed(); 205 206 QList<QListWidgetItem*> items = ui.lstAliases->findItems(alias, Qt::MatchFixedString); 207 items.removeAll(item); 208 if (items.count() > 0){ // Is it already in the list? 209 QMessageBox::information(this, tr("SMSSender"), 210 tr("This contact is already known under this alias."), 211 QMessageBox::Ok | QMessageBox::Default | QMessageBox::Escape); 212 ui.lstAliases->editItem(item); 213 return; 214 } 215 216 ui.lstAliases->takeItem(ui.lstAliases->row(item)); 217 foreach (QString newAlias, alias.split(",", QString::SkipEmptyParts)) { 218 newAlias = newAlias.trimmed(); 219 220 if (ui.lstAliases->findItems(newAlias, Qt::MatchFixedString).count() == 0){ // Is it already in the list? 221 addAliasItem(newAlias); 222 } 223 } 224 // ui.lstAliases->sortItems(); 225 } 226 227 /*void VCEditContact::on_lstAliases_itemDoubleClicked(QListWidgetItem* item){ 153 228 QString alias = editAlias(item->text()); 154 229 155 if (alias == ""){ 156 if (QMessageBox::Yes == QMessageBox::information(this, tr("SMSSender"), 157 tr("You entered a empty value. Do you want to delete this alias?"), 158 QMessageBox::Yes, 159 QMessageBox::No | QMessageBox::Default | QMessageBox::Escape)) { 160 ui.lstAliases->takeItem(ui.lstAliases->row(item)); 161 } 162 }else{ 163 item->setText(alias); 164 } 165 } 230 }*/ 166 231 167 232 void VCEditContact::on_btnRemoveAlias_clicked(){ … … 170 235 } 171 236 172 if (QMessageBox::Yes == QMessageBox::warning(this, tr("SMSSender"), 173 tr("Do you really want to remove this alias?"), 174 QMessageBox::Yes, 175 QMessageBox::No | QMessageBox::Default | QMessageBox::Escape)){ 237 if ((ui.lstAliases->selectedItems().first()->text().trimmed() == "") || 238 (QMessageBox::Yes == QMessageBox::warning(this, tr("SMSSender"), 239 tr("Do you really want to remove this alias?"), 240 QMessageBox::Yes, 241 QMessageBox::No | QMessageBox::Default | QMessageBox::Escape))){ 176 242 // Remove it from the list 177 243 ui.lstAliases->takeItem(ui.lstAliases->row(ui.lstAliases->selectedItems().first())); … … 199 265 200 266 contact_->setName(ui.edtName->text()); 201 // TODO: test some different formats 202 contact_->setNumber(SNumber(ui.edtNumber->text())); 203 267 contact_->setNumber(SNumber(ui.edtCountryCode->text() + " " + ui.edtNumber->text(), SNumber::GuessFormat)); 204 268 QStringList aliases; 205 269 for (int x = 0; x < ui.lstAliases->count(); x++){ 206 aliases.append(ui.lstAliases->item(x)->text()); 270 QString alias = ui.lstAliases->item(x)->text().trimmed(); 271 if (alias != "") { 272 aliases.append(alias); 273 } 207 274 } 208 275 contact_->setAliases(aliases); 209 276 210 contactImage_ = contactImage_.scaledToHeight(72, Qt::SmoothTransformation);211 277 contact_->setImage(contactImage_); 212 278 -
src/ui/VCEditContact/vceditcontact.h
r43 r56 13 13 public: 14 14 VCEditContact(IContact* contact, QWidget *parent = 0); 15 ~VCEditContact() {};15 ~VCEditContact(); 16 16 17 17 private: … … 21 21 QImage contactImage_; 22 22 23 QString editAlias(const QString& alias); 23 //QString editAlias(const QString& alias); 24 QListWidgetItem* addAliasItem(const QString& alias); 24 25 25 26 void addBtnIconMenu(); … … 36 37 37 38 void on_btnAddAlias_clicked(); 39 void on_btnEditAlias_clicked(); 38 40 void on_btnRemoveAlias_clicked(); 39 void on_lstAliases_itemDoubleClicked(QListWidgetItem* item); 41 // void on_lstAliases_itemDoubleClicked(QListWidgetItem* item); 42 void on_lstAliases_itemChanged(QListWidgetItem* item); 40 43 void on_lstAliases_itemSelectionChanged(); 41 44 -
src/ui/VCEditContact/vceditcontact.ui
r22 r56 30 30 <string>Contact information</string> 31 31 </property> 32 <layout class="Q FormLayout" name="formLayout">32 <layout class="QGridLayout" name="gridLayout_3"> 33 33 <item row="0" column="0"> 34 34 <widget class="QLabel" name="label"> … … 38 38 </widget> 39 39 </item> 40 <item row="0" column="1" >40 <item row="0" column="1" colspan="2"> 41 41 <widget class="QLineEdit" name="edtName"/> 42 42 </item> … … 49 49 </item> 50 50 <item row="1" column="1"> 51 <widget class="QLineEdit" name="edtCountryCode"> 52 <property name="sizePolicy"> 53 <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> 54 <horstretch>0</horstretch> 55 <verstretch>0</verstretch> 56 </sizepolicy> 57 </property> 58 <property name="maximumSize"> 59 <size> 60 <width>41</width> 61 <height>16777215</height> 62 </size> 63 </property> 64 </widget> 65 </item> 66 <item row="1" column="2"> 51 67 <widget class="QLineEdit" name="edtNumber"/> 52 68 </item> … … 141 157 </item> 142 158 <item row="0" column="2"> 159 <widget class="QPushButton" name="btnEditAlias"> 160 <property name="minimumSize"> 161 <size> 162 <width>34</width> 163 <height>34</height> 164 </size> 165 </property> 166 <property name="maximumSize"> 167 <size> 168 <width>34</width> 169 <height>34</height> 170 </size> 171 </property> 172 <property name="toolTip"> 173 <string>Edit account</string> 174 </property> 175 <property name="text"> 176 <string/> 177 </property> 178 <property name="icon"> 179 <iconset resource="../../../lib/resource.qrc"> 180 <normaloff>:/ico/edit.png</normaloff>:/ico/edit.png</iconset> 181 </property> 182 </widget> 183 </item> 184 <item row="0" column="3"> 143 185 <spacer name="horizontalSpacer"> 144 186 <property name="orientation"> … … 153 195 </spacer> 154 196 </item> 155 <item row="1" column="0" colspan=" 3">197 <item row="1" column="0" colspan="4"> 156 198 <widget class="QListWidget" name="lstAliases"> 199 <property name="editTriggers"> 200 <set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set> 201 </property> 202 <property name="alternatingRowColors"> 203 <bool>true</bool> 204 </property> 157 205 <property name="sortingEnabled"> 158 206 <bool>true</bool> -
src/ui/VCMain/vcmain.cpp
r43 r56 9 9 #include <algorithm> 10 10 11 #include <snumber.h> 12 #include <typeconvert.h> 13 14 #include <icontact.h> 15 16 #include "../../business/BusinessFactory.h" 11 17 #include "../../business/BCAccountManager.h" 12 18 #include "../../business/BCContactManager.h" 13 19 #include "../../business/BCGroupManager.h" 14 20 15 #include <typeconvert.h>16 17 21 #include "../UIHelper.h" 18 22 19 23 #include "../VCAccountList/vcaccountlist.h" 20 24 #include "../VCAddressBook/vcaddressbook.h" 25 #include "../VCEditContact/vceditcontact.h" 21 26 #include "../VCSettings/vcsettings.h" 22 27 … … 30 35 ui.setupUi(this); 31 36 32 //contactListModel = new QStringListModel; 33 //contactListModel = new AliasModel; 34 37 /* Accounts */ 38 accountModel_ = new AccountTreeModel(this); 39 accountFilterModel_ = new QSortFilterProxyModel(this); 40 accountFilterModel_->setSourceModel(accountModel_); 41 accountFilterModel_->setSortCaseSensitivity(Qt::CaseInsensitive); 42 accountFilterModel_->setDynamicSortFilter(true); 43 accountFilterModel_->setFilterKeyColumn(AccountTreeModel::ColEnabled); 44 accountFilterModel_->setFilterRole(Qt::CheckStateRole); 45 accountFilterModel_->setFilterFixedString("1"); // Get only enabled ones 46 accountFilterModel_->sort(AccountTreeModel::ColName, Qt::AscendingOrder); 47 ui.lstAccounts->setModel(accountFilterModel_); 48 49 /* Contact / Groups */ 35 50 contactGroupListModel_ = new ContactGroupListModel(this); 36 QSortFilterProxyModel* sortModel = new QSortFilterProxyModel(this); 37 sortModel->setSourceModel(contactGroupListModel_); 38 ui.lstContacts->setModel(sortModel); 51 contactGroupSortModel_ = new QSortFilterProxyModel(this); 52 contactGroupSortModel_->setSourceModel(contactGroupListModel_); 53 contactGroupSortModel_->setDynamicSortFilter(true); 54 contactGroupSortModel_->setSortCaseSensitivity(Qt::CaseInsensitive); 55 contactGroupSortModel_->sort(0, Qt::AscendingOrder); 56 ui.lstContacts->setModel(contactGroupSortModel_); 39 57 40 58 QSortFilterProxyModel* completionModel = new AliasCompletionModel(this); … … 46 64 ui.lstContacts->setCompleter(aliasCompleter); 47 65 ui.lstContacts->completer()->popup()->setIconSize(QSize(24, 24)); 48 //ui.lstContacts->setEditable(true); 49 50 /*connect(ui.lstContacts->lineEdit(), SIGNAL(textChanged()), 51 aliasCompleter, SLOT());*/ 66 52 67 connect(ui.lstContacts->lineEdit(), SIGNAL(returnPressed()), 53 68 this, SLOT(on_btnAddRecipient_clicked())); … … 55 70 connect(aliasCompleter, SIGNAL(highlighted(const QString&)), 56 71 this, SLOT(on_lstContacts_completer_changed(const QString&))); 72 57 73 58 74 connect(BCAccountLoadManager::instance(), SIGNAL(accountLoadStateChanged(IAccount*, AccountLoadState)), … … 64 80 65 81 66 init();67 68 ui.lstContacts->setCurrentIndex(-1);69 }70 71 void VCMain::init(){72 //refillAccountList();73 refillContactList();74 75 82 // First "signal" to initialize some slots 76 83 on_treeRecipients_itemSelectionChanged(); 77 } 78 84 85 ui.lstContacts->setCurrentIndex(-1); 86 } 79 87 80 88 /* Contacts & Recipients... */ 81 82 void VCMain::refillContactList(){83 // TODO: Make usage of aliases...84 /*85 contactListModel->removeRows(0, contactListModel->rowCount());86 //ui.lstContacts->clear();87 contactStrToContact.clear();88 groupStrToGroup.clear();89 90 QPixmap blankIcon = QPixmap(":/ico/blank.png");91 92 foreach (IContact* contact, BCContactManager::instance()->getContactList()) {93 QPixmap icon = QPixmap::fromImage(contact->image());94 if (icon.isNull()){95 icon = blankIcon;96 }97 QString contactStr = contact->name();98 QString aliasStr;99 QStringListIterator i(contact->aliases());100 while (i.hasNext()) {101 aliasStr += i.next() + ", ";102 }103 aliasStr.remove(QRegExp(", $"));104 if (aliasStr != "") {105 contactStr += " (" + aliasStr + ")";106 }107 108 contactListModel->insertRow(contactListModel->rowCount());109 contactListModel->setData(contactListModel->index(contactListModel->rowCount() - 1, 0), QIcon(icon), Qt::DecorationRole);110 contactListModel->setData(contactListModel->index(contactListModel->rowCount() - 1, 0), contactStr, Qt::DisplayRole);111 112 //ui.lstContacts->addItem(QIcon(icon), contactStr);113 contactStrToContact.insert(contactStr, contact);114 }115 116 foreach (IGroup* group, BCGroupManager::instance()->getGroupList()) {117 QPixmap icon = QPixmap::fromImage(group->image());118 if (icon.isNull()){119 icon = blankIcon;120 }121 122 QString groupStr = "<" + group->name() + ">";123 124 contactListModel->insertRow(contactListModel->rowCount());125 contactListModel->setData(contactListModel->index(contactListModel->rowCount() - 1, 0), QIcon(icon), Qt::DecorationRole);126 contactListModel->setData(contactListModel->index(contactListModel->rowCount() - 1, 0), groupStr, Qt::DisplayRole);127 // ui.lstContacts->addItem(QIcon(icon), "<" + group->name() + ">");128 groupStrToGroup.insert(groupStr, group);129 }130 ui.lstContacts->model()->sort(0);131 132 //ui.lstContacts->insertItem(0, blankIcon, ""); // Empty item at first position to prevent default recipient selection133 ui.lstContacts->setCurrentIndex(-1); */134 }135 136 137 89 bool VCMain::isContactNode(const QTreeWidgetItem* node){ 138 90 return nodeToContact.contains(const_cast<QTreeWidgetItem*>(node)); … … 218 170 } 219 171 172 // TODO: Check if the given recipient/number is a valid recipient for the selected gateway 173 220 174 contactGroupListModel_->addFilteredContact(contact); 221 175 … … 281 235 282 236 void VCMain::reloadAccountList() { 283 accountStrToAccount.clear();237 /* accountStrToAccount.clear(); 284 238 QComboBox* accLst = ui.lstAccounts; 285 239 … … 294 248 int index = accLst->findText(selectedAccount); 295 249 index = std::max(index, 0); 296 accLst->setCurrentIndex(index); 250 accLst->setCurrentIndex(index);*/ 297 251 } 298 252 … … 311 265 312 266 void VCMain::sendMessage() { 313 IAccount* account = accountStrToAccount[ui.lstAccounts->currentText()]; 267 QModelIndex idx = accountFilterModel_->mapToSource(accountFilterModel_->index(ui.lstAccounts->currentIndex(), 0)); 268 IAccount* account = accountModel_->dataObject(idx); 314 269 QString message = ui.txtMessage->toPlainText().trimmed(); 315 270 QSet<IContact*> recipients = getRecipientContacts(true); 316 271 317 account->sendSMS(message, recipients); 318 QMessageBox::information(this, tr("SMS sent"), tr("Your sms has successfully been sent."), QMessageBox::Ok, QMessageBox::Ok); 272 if (account != NULL) { 273 account->sendSMS(message, recipients); 274 QMessageBox::information(this, tr("SMS sent"), tr("Your sms has successfully been sent."), QMessageBox::Ok, QMessageBox::Ok); 275 } 319 276 } 320 277 … … 337 294 338 295 void VCMain:: on_btnAddRecipient_clicked(){ 339 QModelIndex idx = contactGroup ListModel_->index(ui.lstContacts->currentIndex());296 QModelIndex idx = contactGroupSortModel_->mapToSource(contactGroupSortModel_->index(ui.lstContacts->currentIndex(), 0)); 340 297 if (idx.isValid()) { 341 298 IInterface* recipient = contactGroupListModel_->dataObject(idx); … … 343 300 addRecipient(dynamic_cast<IGroup*>(recipient)); 344 301 } else { 345 // TODO: Add new numbers to the address book 302 SNumber number = SNumber::fromString(ui.lstContacts->lineEdit()->text().trimmed(), SNumber::GuessFormat); 303 if (!number.isValid()) { 304 number = SNumber::fromString("+41 " + ui.lstContacts->lineEdit()->text().trimmed(), SNumber::GuessFormat); 305 } 306 if (number.isValid()) { 307 IContact* recipient = BCContactManager::instance()->getContactByNumber(number); 308 309 if (recipient != NULL) { 310 addRecipient(recipient); 311 } else { 312 IContact* recipient = BusinessFactory::instance()->getContactInstance(); 313 recipient->setNumber(number); 314 315 if (QMessageBox::Yes == QMessageBox::question(this, tr("SMSSender"), 316 tr("This number is not yet in your address book. Do you want to add it?"), 317 QMessageBox::Yes, 318 QMessageBox::No | QMessageBox::Default | QMessageBox::Escape)){ 319 VCEditContact* ec = new VCEditContact(recipient, this); 320 if (ec->exec() == QDialog::Accepted){ // Wait for return 321 BCContactManager::instance()->saveContact(recipient); 322 } 323 } 324 if (recipient->name() == "") { 325 recipient->setName(number.toString(SNumber::IsoFormatShort)); 326 } 327 addRecipient(recipient); 328 } 329 } 346 330 } 347 331 ui.lstContacts->setCurrentIndex(-1); -
src/ui/VCMain/vcmain.h
r43 r56 2 2 #define VCMAIN_H 3 3 4 #include "ui_vcmain.h" 5 4 6 #include <QStringListModel> 5 7 #include <QMap> 6 #include <QtGui/QMainWindow> 7 #include <QtGui/QTreeWidgetItem> 8 #include <QMainWindow> 9 #include <QTreeWidgetItem> 10 #include <QSortFilterProxyModel> 8 11 9 12 #include <icontact.h> … … 12 15 #include "../../business/BCAccountLoadManager.h" 13 16 14 #include "ui_vcmain.h" 15 17 #include "../models/accounttreemodel.h" 16 18 #include "../models/contactgroupmodel.h" 17 19 … … 26 28 Ui::VCMainClass ui; 27 29 30 AccountTreeModel* accountModel_; 31 QSortFilterProxyModel* accountFilterModel_; 32 28 33 ContactGroupListModel* contactGroupListModel_; 29 // QStringListModel* contactListModel;34 QSortFilterProxyModel* contactGroupSortModel_; 30 35 31 36 QMap<QString, IAccount*> accountStrToAccount; 32 /*QMap<QString, IContact*> contactStrToContact;33 QMap<QString, IGroup*> groupStrToGroup;*/34 37 35 38 QMap<QTreeWidgetItem*, IContact*> nodeToContact; 36 39 QMap<QTreeWidgetItem*, IGroup*> nodeToGroup; 37 40 38 void init();39 void refillContactList();40 41 41 /* Recipient list */ 42 bool isContactNode(const QTreeWidgetItem* node);43 bool isGroupNode(const QTreeWidgetItem* node);44 IContact* getContactOfNode(const QTreeWidgetItem* node);45 IGroup* getGroupOfNode(const QTreeWidgetItem* node);46 bool isNodeContactOrHasContact(const QTreeWidgetItem* node, IContact* contact);47 bool isContactAlreadyRecipient(IContact* contact);48 bool isGroupAlreadyRecipient(IGroup* group);42 bool isContactNode(const QTreeWidgetItem* node); 43 bool isGroupNode(const QTreeWidgetItem* node); 44 IContact* getContactOfNode(const QTreeWidgetItem* node); 45 IGroup* getGroupOfNode(const QTreeWidgetItem* node); 46 bool isNodeContactOrHasContact(const QTreeWidgetItem* node, IContact* contact); 47 bool isContactAlreadyRecipient(IContact* contact); 48 bool isGroupAlreadyRecipient(IGroup* group); 49 49 50 50 void addRecipient(IContact* contact, QTreeWidgetItem* parent = NULL); … … 56 56 QSet<IGroup*> getRecipientGroups(); 57 57 58 /* Account */ 58 59 void reloadAccountList(); 60 59 61 void enableSendBtnIfAllFilled(); 60 62 -
src/ui/models/accounttreemodel.cpp
r55 r56 1 #include "account model.h"1 #include "accounttreemodel.h" 2 2 3 3 #include <QDebug> 4 4 5 Account Model::AccountModel(QObject* parent)5 AccountTreeModel::AccountTreeModel(QObject* parent) 6 6 : QAbstractTableModel(parent) 7 7 { 8 8 connect(BCAccountManager::instance(), SIGNAL(accountAdded(IAccount*)), 9 9 this, SLOT(accountUpdated(IAccount*))); 10 connect(BCAccountManager::instance(), SIGNAL(account DataChanged(IAccount*)),10 connect(BCAccountManager::instance(), SIGNAL(accountUpdated(IAccount*)), 11 11 this, SLOT(accountUpdated(IAccount*))); 12 12 connect(BCAccountManager::instance(), SIGNAL(accountRemoved(IAccount*)), 13 13 this, SLOT(accountUpdated(IAccount*))); 14 14 } 15 Account Model::~AccountModel() {15 AccountTreeModel::~AccountTreeModel() { 16 16 disconnect(BCAccountManager::instance(), SIGNAL(accountAdded(IAccount*)), 17 17 this, SLOT(accountUpdated(IAccount*))); 18 disconnect(BCAccountManager::instance(), SIGNAL(account DataChanged(IAccount*)),18 disconnect(BCAccountManager::instance(), SIGNAL(accountUpdated(IAccount*)), 19 19 this, SLOT(accountUpdated(IAccount*))); 20 20 disconnect(BCAccountManager::instance(), SIGNAL(accountRemoved(IAccount*)), … … 22 22 } 23 23 24 void Account Model::accountUpdated(IAccount* account) {24 void AccountTreeModel::accountUpdated(IAccount* account) { 25 25 int row = BCAccountManager::instance()->getAccountList().values().indexOf(account); 26 26 … … 35 35 } 36 36 37 QVariant Account Model::headerData(int section, Qt::Orientation orientation, int role) const {37 QVariant AccountTreeModel::headerData(int section, Qt::Orientation orientation, int role) const { 38 38 if (orientation == Qt::Horizontal) { 39 39 if (role == Qt::DisplayRole) { … … 51 51 } 52 52 53 IAccount* Account Model::dataObject(const QModelIndex& index) const {53 IAccount* AccountTreeModel::dataObject(const QModelIndex& index) const { 54 54 return BCAccountManager::instance()->getAccountList().values().at(index.row()); 55 55 } 56 56 57 QVariant Account Model::data(const QModelIndex& index, int role) const {57 QVariant AccountTreeModel::data(const QModelIndex& index, int role) const { 58 58 QList<IAccount*> accounts = BCAccountManager::instance()->getAccountList().values(); 59 59 if (!index.isValid() || index.row() < 0 || index.row() >= accounts.size()) … … 96 96 } 97 97 98 Qt::ItemFlags Account Model::flags(const QModelIndex& index) const {98 Qt::ItemFlags AccountTreeModel::flags(const QModelIndex& index) const { 99 99 if (!index.isValid()) 100 100 return Qt::ItemIsEnabled; … … 106 106 } 107 107 108 bool Account Model::setData(const QModelIndex& index, const QVariant& value, int role /* = Qt::EditRole */) {108 bool AccountTreeModel::setData(const QModelIndex& index, const QVariant& value, int role /* = Qt::EditRole */) { 109 109 if (!index.isValid()) { 110 110 return false; … … 127 127 } 128 128 129 int Account Model::columnCount(const QModelIndex& parent) const {129 int AccountTreeModel::columnCount(const QModelIndex& parent) const { 130 130 return (parent.isValid()) ? 0 : MaxCol+1; 131 131 } 132 132 133 int Account Model::rowCount(const QModelIndex& parent) const {133 int AccountTreeModel::rowCount(const QModelIndex& parent) const { 134 134 return (parent.isValid()) ? 0 : BCAccountManager::instance()->getAccountList().count(); 135 135 } 136 136 137 bool Account Model::removeRows(int row, int count, const QModelIndex& parent) {137 bool AccountTreeModel::removeRows(int row, int count, const QModelIndex& parent) { 138 138 if (parent.isValid()) 139 139 return false; -
src/ui/models/accounttreemodel.h
r55 r56 1 #ifndef UI_ACCOUNT MODEL_H2 #define UI_ACCOUNT MODEL_H1 #ifndef UI_ACCOUNTTREEMODEL_H 2 #define UI_ACCOUNTTREEMODEL_H 3 3 4 4 #include <QObject> … … 8 8 #include "../../business/BCAccountManager.h" 9 9 10 class Account Model: public QAbstractTableModel {10 class AccountTreeModel: public QAbstractTableModel { 11 11 Q_OBJECT 12 12 … … 15 15 16 16 public: 17 Account Model(QObject* parent = 0);18 ~Account Model();17 AccountTreeModel(QObject* parent = 0); 18 ~AccountTreeModel(); 19 19 20 20 enum Columns { … … 38 38 39 39 40 #endif // UI_ACCOUNT MODEL_H40 #endif // UI_ACCOUNTTREEMODEL_H 41 41
Note: See TracChangeset
for help on using the changeset viewer.