source: SMSSender/frontend/gui/ui/addressbook/addressbook_contact.cpp @ 315:e6c8bb244ecd

separation-frontend-backend
Last change on this file since 315:e6c8bb244ecd was 315:e6c8bb244ecd, checked in by Sämy Zehnder <saemy.zehnder@…>, 6 years ago
  • Separates the frontend from the backend code.
  • At this point the schoolnet gateway is converted only.
  • Removes bc & da prefixes from the filenames.
File size: 3.4 KB
Line 
1/*
2 smssender - A frontend for fast and easy SMS sending over different gateways.
3 Copyright (C) 2007-2012, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "addressbook.h"
19
20#include <QMessageBox>
21#include <QScopedPointer>
22
23#include "frontend/business/contactimportermanager.h"
24#include "frontend/business/contactmanager.h"
25#include "frontend/gui/ui/editcontact/editcontact.h"
26#include "frontend/gui/ui/importcontacts/importcontactswizard.h"
27
28namespace UI {
29
30SContact *AddressBook::getContactFromRow(int rowId) const {
31    QModelIndex idx = contactProxyModel_->mapToSource(contactProxyModel_->index(rowId, 0));
32    return contactModel_->dataObject(idx);
33}
34
35SContact *AddressBook::getSelectedContact() const {
36    QItemSelectionModel* ism = ui.tblViewContacts->selectionModel();
37    if (!ism->hasSelection())
38        return NULL;
39
40    int row = ism->selectedRows().first().row();
41    return getContactFromRow(row);
42}
43
44
45void AddressBook::editContact(SContact *contact) {
46    QScopedPointer<EditContact> ec(new EditContact(this, contact, false, *m_contactManager, *m_groupManager));
47    if (ec->exec() == QDialog::Accepted){ // Wait for return
48        m_contactManager->saveContact(contact);
49    }
50}
51
52
53// Slots
54
55void AddressBook::on_btnAddContact_clicked(){
56    if (!ui.btnAddContact->isEnabled())
57        return;
58
59    SContact newContact;
60    editContact(&newContact);
61}
62
63void AddressBook::on_btnEditContact_clicked(){
64    if (!ui.btnEditContact->isEnabled())
65        return;
66
67    SContact *contact = getSelectedContact();
68    if (!contact)
69        return;
70
71    editContact(contact);
72}
73
74void AddressBook::on_btnRemoveContact_clicked(){
75    if (!ui.btnRemoveContact->isEnabled())
76        return;
77
78    const SContact *contact = getSelectedContact();
79    if (!contact)
80        return;
81
82    if (QMessageBox::Yes == QMessageBox::warning(this, tr("SMSSender"),
83                                                 tr("Do you really want to remove this contact?"),
84                                                 QMessageBox::Yes,
85                                                 QMessageBox::No | QMessageBox::Default | QMessageBox::Escape)) {
86        m_contactManager->removeContact(contact->id());
87        on_tblViewContacts_selectionChanged();
88    }
89}
90
91void AddressBook::on_btnImportContacts_clicked() {
92    QScopedPointer<ImportContactsWizard> w(new ImportContactsWizard(this, m_contactImporterManager.contactImporters(),
93                                                                    m_contactManager, *m_groupManager, m_guiManager));
94    w->exec();
95}
96
97void AddressBook::on_tblViewContacts_selectionChanged() {
98    ui.btnEditContact->setEnabled(ui.tblViewContacts->selectionModel()->hasSelection());
99    ui.btnRemoveContact->setEnabled(ui.tblViewContacts->selectionModel()->hasSelection());
100}
101
102} // namespace UI
Note: See TracBrowser for help on using the repository browser.