-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcambiaaccount.cpp
More file actions
158 lines (131 loc) · 5.21 KB
/
cambiaaccount.cpp
File metadata and controls
158 lines (131 loc) · 5.21 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
/*
Copyright (C) <2011>
<enrico bacis> <enrico.bacis@gmail.com>
<ivan vaccari> <grisson@jacksms.it>
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 "cambiaaccount.h"
#include "ui_cambiaaccount.h"
#include <libjacksms/libJackSMS.h>
cambiaaccount::cambiaaccount(QWidget *parent, MainJackSMS *_padre, const libJackSMS::dataTypes::servicesType &_ElencoServizi, const libJackSMS::dataTypes::configuredServicesType &_ElencoServiziConfigurati, libJackSMS::dataTypes::phoneBookType &_Rubrica, QString _id, int _found) :
QDialog(parent),
m_ui(new Ui::cambiaaccount),
padre(_padre),
ElencoServizi(_ElencoServizi),
ElencoServiziConfigurati(_ElencoServiziConfigurati),
Rubrica(_Rubrica),
id(_id),
found(_found)
{
m_ui->setupUi(this);
if (found == 1)
m_ui->label->setText("E' stato trovato un contatto avente il servizio cancellato come account associato. Si può associare automaticamente questo contatto a un altro servizio.");
else
m_ui->label->setText("Sono stati trovati " + QString::number(found) + " contatti aventi il servizio cancellato come account associato. Si possono associare automaticamente questi contatti a un altro servizio.");
changed = 0;
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();
{
for(libJackSMS::dataTypes::configuredServicesType::const_iterator i = ElencoServiziConfigurati.begin(); i != ElencoServiziConfigurati.end(); ++i)
m_ui->comboaccount->addItem(_ElencoServizi[i->getService()].getIcon(),i->getName());
m_ui->comboaccount->model()->sort(0);
}
}
cambiaaccount::~cambiaaccount()
{
delete m_ui;
}
void cambiaaccount::on_buttonSalva_clicked()
{
stopsearch = false;
m_ui->buttonSalva->setEnabled(false);
m_ui->buttonAnnulla->setEnabled(false);
m_ui->comboaccount->setEnabled(false);
m_ui->labelSpin->show();
try
{
QString idAccount;
{
QString nomeAccount = m_ui->comboaccount->currentText();
for (libJackSMS::dataTypes::configuredServicesType::const_iterator x = ElencoServiziConfigurati.begin(); x != ElencoServiziConfigurati.end(); ++x)
{
if (x.value().getName() == nomeAccount)
{
idAccount = x.value().getId();
break;
}
}
}
saver = new libJackSMS::serverApi::contactManager(padre->current_login_id);
connect(saver, SIGNAL(contactUpdated(libJackSMS::dataTypes::contact)), this, SLOT(salvataggioOk(libJackSMS::dataTypes::contact)));
connect(saver, SIGNAL(contactNotUpdated()), this, SLOT(salvataggioKo()));
for (libJackSMS::dataTypes::phoneBookType::iterator i = Rubrica.begin(); i != Rubrica.end(); ++i)
{
if(i->getAccount() == id)
{
libJackSMS::dataTypes::contact contatto(i->getName(), i->getPhone(), i->getGroup(), idAccount);
contatto.setId(i->getId());
i->setAccount(idAccount);
if (stopsearch)
break;
saver->updateContact(contatto);
}
}
} catch(...) {
salvataggioKo();
}
//non dovrebbe mai arrivare qui ma per precauzione..
if (!stopsearch)
close();
}
void cambiaaccount::on_buttonAnnulla_clicked()
{
close();
}
void cambiaaccount::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type())
{
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
void cambiaaccount::salvataggioOk(libJackSMS::dataTypes::contact c)
{
Rubrica[c.getId()] = c;
++changed;
if(changed == found)
{
padre->ReWriteAddressBookToGui();
QMessageBox::information(this, "Freesmee", "Contatti modificati.");
close();
}
}
void cambiaaccount::salvataggioKo()
{
stopsearch = true;
m_ui->buttonSalva->setEnabled(true);
m_ui->buttonSalva->setEnabled(true);
m_ui->comboaccount->setEnabled(true);
m_ui->labelSpin->hide();
if (found == 1)
QMessageBox::critical(this, "Freesmee", "Si e' verificato un errore durante l'aggiornamento del contatto. Riprova.");
else
QMessageBox::critical(this, "Freesmee", "Si e' verificato un errore durante l'aggiornamento dei contatti. Riprova.");
}