~ubuntu-branches/ubuntu/raring/recorditnow/raring

« back to all changes in this revision

Viewing changes to src/upload/accountpage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-09 14:54:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110109145401-gyckb4airz4fio50
Tags: 0.8.1-0ubuntu1
* New upstream release. (LP: #681270)
  - Update debian/copyright.
* Build-depend on recordmydesktop.
* Add a watch file.
* Drop 01_fix_ftbfs_kwarning_call.diff, fixed upstream.
* Add 01_joschy_install_to_usr_lib.diff.
* Add 02_fix_ftbfs_no-add-needed.diff.
* Add 03_dont_install_header_files.diff.
* Replace dependency on libpolkit-qt-1-0 with policykit-1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 by Kai Dombrowe <just89@gmx.de>                    *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
18
 ***************************************************************************/
 
19
 
 
20
// own
 
21
#include "accountpage.h"
 
22
#include <recorditnow.h>
 
23
 
 
24
// KDE
 
25
#include <kdebug.h>
 
26
#include <kwallet.h>
 
27
 
 
28
 
 
29
 
 
30
AccountPage::AccountPage(QWidget *parent)
 
31
    : QWizardPage(parent), m_wallet(0)
 
32
{
 
33
 
 
34
    setupUi(this);
 
35
 
 
36
    registerField("Account*", accountEdit);
 
37
    registerField("Password*", passwordEdit);
 
38
 
 
39
}
 
40
 
 
41
 
 
42
AccountPage::~AccountPage()
 
43
{
 
44
 
 
45
    if (m_wallet) {
 
46
        delete m_wallet;
 
47
    }
 
48
 
 
49
}
 
50
 
 
51
 
 
52
void AccountPage::initializePage()
 
53
{
 
54
 
 
55
    wallCheck->setChecked(Settings::uploadPassword());
 
56
    if (wallCheck->isChecked()) {
 
57
        KConfigGroup cfg(Settings::self()->config(), "Upload");
 
58
        accountEdit->setText(cfg.readEntry("RecordItNow-"+field("Provider").toString(), QString()));
 
59
        getPassword();
 
60
    }
 
61
 
 
62
}
 
63
 
 
64
 
 
65
 
 
66
void AccountPage::writeWallet(bool success)
 
67
{
 
68
 
 
69
    kDebug() << "success:" << success;
 
70
    if (success && enterWalletFolder("RecordItNow-"+field("Provider").toString())) {
 
71
        if (m_wallet->writePassword(accountEdit->text(), passwordEdit->text()) == 0) {
 
72
            kDebug() << "successfully put password in wallet";
 
73
        }
 
74
    }
 
75
 
 
76
    m_walletWait = None;
 
77
    delete m_wallet;
 
78
    m_wallet = 0;
 
79
 
 
80
}
 
81
 
 
82
 
 
83
void AccountPage::readWallet(bool success)
 
84
{
 
85
 
 
86
    kDebug() << "success:" << success;
 
87
    if (success && enterWalletFolder("RecordItNow-"+field("Provider").toString())) {
 
88
        QString password;
 
89
        if (m_wallet->readPassword(accountEdit->text(), password) == 0) {
 
90
            kDebug() << "successfully retrieved password from wallet";
 
91
            passwordEdit->setText(password);
 
92
        }
 
93
    }
 
94
 
 
95
    m_walletWait = None;
 
96
    delete m_wallet;
 
97
    m_wallet = 0;
 
98
 
 
99
}
 
100
 
 
101
 
 
102
void AccountPage::getWallet()
 
103
{
 
104
 
 
105
    if (m_wallet) {
 
106
        delete m_wallet;
 
107
    }
 
108
 
 
109
    kDebug() << "opening wallet";
 
110
    m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), winId(),
 
111
                                           KWallet::Wallet::Asynchronous);
 
112
 
 
113
    if (m_walletWait == Write) {
 
114
        connect(m_wallet, SIGNAL(walletOpened(bool)), SLOT(writeWallet(bool)));
 
115
    } else {
 
116
        connect(m_wallet, SIGNAL(walletOpened(bool)), SLOT(readWallet(bool)));
 
117
    }
 
118
 
 
119
}
 
120
 
 
121
 
 
122
bool AccountPage::enterWalletFolder(const QString &folder)
 
123
{
 
124
 
 
125
    if (!m_wallet) {
 
126
        return false;
 
127
    }
 
128
 
 
129
    m_wallet->createFolder(folder);
 
130
    if (!m_wallet->setFolder(folder)) {
 
131
        kDebug() << "failed to open folder" << folder;
 
132
        return false;
 
133
    }
 
134
    kDebug() << "wallet now on folder" << folder;
 
135
    return true;
 
136
 
 
137
}
 
138
 
 
139
 
 
140
bool AccountPage::validatePage()
 
141
{
 
142
 
 
143
    Settings::self()->setUploadPassword(wallCheck->isChecked());
 
144
    if (wallCheck->isChecked()) {
 
145
        KConfigGroup cfg(Settings::self()->config(), "Upload");
 
146
        cfg.writeEntry("RecordItNow-"+field("Provider").toString(), accountEdit->text());
 
147
        setPassword();
 
148
    }
 
149
    return true;
 
150
 
 
151
}
 
152
 
 
153
 
 
154
void AccountPage::getPassword()
 
155
{
 
156
 
 
157
    if (accountEdit->text().isEmpty()) {
 
158
        return;
 
159
    }
 
160
    m_walletWait = Read;
 
161
    getWallet();
 
162
 
 
163
}
 
164
 
 
165
 
 
166
void AccountPage::setPassword()
 
167
{
 
168
 
 
169
    if (accountEdit->text().isEmpty() || passwordEdit->text().isEmpty()) {
 
170
        return;
 
171
    }
 
172
    m_walletWait = Write;
 
173
    getWallet();
 
174
 
 
175
}
 
176
 
 
177
 
 
178
#include "accountpage.moc"