-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditcontattodialog.cpp
146 lines (119 loc) · 5.2 KB
/
editcontattodialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Copyright (C) <2011>
<enrico bacis> <[email protected]>
<ivan vaccari> <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "editcontattodialog.h"
#include "ui_editcontattodialog.h"
#include <QProcess>
#include <Configuration.h>
#include <QMessageBox>
editcontattodialog::editcontattodialog(QWidget *parent, const libJackSMS::dataTypes::servicesType &_ElencoServizi, const libJackSMS::dataTypes::configuredServicesType &_ElencoServiziConfigurati, libJackSMS::dataTypes::phoneBookType &_Rubrica, QString contactId, QString _current_login_id) :
QDialog(parent),
m_ui(new Ui::editcontattodialog),
ElencoServizi(_ElencoServizi),
ElencoServiziConfigurati(_ElencoServiziConfigurati),
Rubrica(_Rubrica),
id(contactId),
current_login_id(_current_login_id)
{
m_ui->setupUi(this);
spinner = new QMovie(":/resource/loading-spinner.gif", QByteArray("gif"), this);
spinner->setScaledSize(QSize(16, 16));
spinner->start();
m_ui->labelSpin->setMovie(spinner);
m_ui->labelSpin->hide();
m_ui->radioEsistente->hide();
m_ui->radioNuovo->hide();
m_ui->ComboGruppo->hide();
m_ui->nuovogruppo->hide();
m_ui->autoDetectButton->hide();
libJackSMS::dataTypes::contact contatto(Rubrica[contactId]);
{
for (libJackSMS::dataTypes::configuredServicesType::const_iterator i = ElencoServiziConfigurati.begin(); i != ElencoServiziConfigurati.end(); ++i) {
if ((i.value().getId() != "1") && (i.value().getId() != "2"))
m_ui->comboaccount->addItem(ElencoServizi[i.value().getService()].getIcon(),i.value().getName());
}
m_ui->comboaccount->model()->sort(0);
m_ui->comboaccount->insertItem(0, ElencoServizi[ElencoServiziConfigurati["1"].getService()].getIcon(), ElencoServiziConfigurati["1"].getName());
m_ui->comboaccount->insertItem(1, ElencoServizi[ElencoServiziConfigurati["2"].getService()].getIcon(), ElencoServiziConfigurati["2"].getName());
}
m_ui->nome->setText(contatto.getName());
m_ui->intPref->setText(contatto.getPhone().getIntPref());
m_ui->pref->setText(contatto.getPhone().getPref());
m_ui->num->setText(contatto.getPhone().getNum());
//m_ui->ComboGruppo->setCurrentIndex(m_ui->ComboGruppo->findText(Rubrica[nameContact].gruppo));
m_ui->comboaccount->setCurrentIndex(m_ui->comboaccount->findText(ElencoServiziConfigurati[contatto.getAccount()].getName()));
}
editcontattodialog::~editcontattodialog()
{
delete m_ui;
}
void editcontattodialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type())
{
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
void editcontattodialog::on_annulla_clicked()
{
close();
}
void editcontattodialog::on_salva_clicked()
{
QString nome = m_ui->nome->text();
libJackSMS::dataTypes::phoneNumber num;
bool numeroValido;
numeroValido = num.parse( (m_ui->intPref->text().isEmpty() ? "" : m_ui->intPref->text() + ".") + m_ui->pref->text() + "." + m_ui->num->text());
if (!numeroValido) {
QMessageBox::critical(this, "Attenzione", "Il numero inserito non è valido, ricontrollalo, oppure se trovi che questo sia un errore segnalalo, grazie.");
return;
}
QString idAccount = "";
{
QString nomeAccount = m_ui->comboaccount->currentText();
for (libJackSMS::dataTypes::configuredServicesType::const_iterator i = ElencoServiziConfigurati.begin(); i != ElencoServiziConfigurati.end(); ++i) {
if (i.value().getName() == nomeAccount) {
idAccount = i.value().getId();
break;
}
}
}
libJackSMS::dataTypes::contact contatto(nome, num, "", idAccount);
contatto.setId(id);
m_ui->salva->setEnabled(false);
m_ui->annulla->setEnabled(false);
m_ui->labelSpin->show();
saver = new libJackSMS::serverApi::contactManager(current_login_id);
connect(saver, SIGNAL(contactUpdated(libJackSMS::dataTypes::contact)), this, SLOT(salvataggioOk(libJackSMS::dataTypes::contact)));
connect(saver, SIGNAL(contactNotUpdated()), this, SLOT(salvataggioKo()));
saver->updateContact(contatto);
}
void editcontattodialog::salvataggioOk(libJackSMS::dataTypes::contact c)
{
Rubrica[c.getId()] = c;
emit contactEdited(c.getId());
close();
}
void editcontattodialog::salvataggioKo(){
m_ui->salva->setEnabled(true);
m_ui->annulla->setEnabled(true);
m_ui->labelSpin->hide();
QMessageBox::critical(this, "Freesmee", "Si e' verificato un errore durante l'aggiornamento del contatto.");
}