~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/proxy.cpp

  • Committer: Package Import Robot
  • Author(s): Jan Niehusmann
  • Date: 2014-07-01 21:49:34 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140701214934-gt4dkgm94byi4vnn
Tags: 0.15-1
* New upstream version
* set debhelper compat level to 9
* set Standards-Version to 3.9.5 (no further changes)
* add lintian override regarding license-problem-non-free-RFC
* use qconf to regenerate configure script
* implement hardening using buildflags instead of hardening-wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 *
19
19
 */
20
20
 
21
21
#include "proxy.h"
22
22
 
23
 
#include <qlabel.h>
24
 
#include <qlineedit.h>
25
 
#include <qcheckbox.h>
26
 
#include <qlayout.h>
27
 
#include <qcombobox.h>
28
 
#include <qpushbutton.h>
29
 
#include <qdom.h>
30
 
#include <qpointer.h>
31
 
#include <qapplication.h>
32
 
//Added by qt3to4:
 
23
#include <QLabel>
 
24
#include <QLineEdit>
 
25
#include <QCheckBox>
 
26
#include <QLayout>
 
27
#include <QComboBox>
 
28
#include <QPushButton>
 
29
#include <QDomElement>
 
30
#include <QPointer>
 
31
#include <QApplication>
33
32
#include <QHBoxLayout>
34
33
#include <QList>
35
34
 
364
363
        hb->addWidget(d->cb_proxy);
365
364
        d->pb_edit = new QPushButton(tr("Edit..."), this);
366
365
        connect(d->pb_edit, SIGNAL(clicked()), SLOT(doOpen()));
 
366
        connect(d->cb_proxy, SIGNAL(activated(int)), SIGNAL(itemChanged()));
367
367
        hb->addWidget(d->pb_edit);
368
368
 
369
369
        buildComboBox();
424
424
        d->m->openDialog(x);
425
425
}
426
426
 
 
427
 
 
428
//----------------------------------------------------------------------------
 
429
// ProxyForObject
 
430
//----------------------------------------------------------------------------
 
431
const QString defaultItemName = "Default";
 
432
 
 
433
ProxyForObject::ProxyForObject(OptionsTree *o, QObject *parent)
 
434
        : QObject(parent)
 
435
        , ot_(o)
 
436
{
 
437
        loadItem(defaultItemName);
 
438
}
 
439
 
 
440
ProxyForObject::~ProxyForObject()
 
441
{
 
442
}
 
443
 
 
444
QString ProxyForObject::itemForObject(const QString& obj)
 
445
{
 
446
        if(!items_.contains(obj))
 
447
                loadItem(obj);
 
448
 
 
449
        return items_.value(obj);
 
450
}
 
451
 
 
452
void ProxyForObject::save()
 
453
{
 
454
        items_ = tmp_;
 
455
        QString base = "proxy.";
 
456
        foreach(QString obj, items_.keys()) {
 
457
                QString val = items_.value(obj);
 
458
                ot_->setOption(base+obj, QVariant(val));
 
459
        }
 
460
}
 
461
 
 
462
QComboBox* ProxyForObject::getComboBox(ProxyChooser* pc, QWidget* p)
 
463
{
 
464
        tmp_ = items_;
 
465
        pc_ = pc;
 
466
        cb_ = new QComboBox(p);
 
467
        cb_->addItems(items_.keys());
 
468
        cb_->setCurrentIndex(0);
 
469
        currentItemChanged(0);
 
470
 
 
471
        connect(cb_, SIGNAL(currentIndexChanged(int)), SLOT(currentItemChanged(int)));
 
472
        connect(pc_, SIGNAL(itemChanged()), SLOT(updateCurrentItem()));
 
473
 
 
474
        return cb_;
 
475
}
 
476
 
 
477
void ProxyForObject::currentItemChanged(int index)
 
478
{
 
479
        const QString data = cb_->itemText(index);
 
480
        pc_->setCurrentItem(tmp_.value(data));
 
481
}
 
482
 
 
483
void ProxyForObject::loadItem(const QString& obj)
 
484
{
 
485
        QVariant v = ot_->getOption(("proxy." + obj));
 
486
        if(!v.isValid())
 
487
                v = ot_->getOption(("proxy." + defaultItemName));
 
488
        items_[obj] = v.toString();
 
489
}
 
490
 
 
491
void ProxyForObject::updateCurrentItem()
 
492
{
 
493
        tmp_[cb_->currentText()] = pc_->currentItem();
 
494
}
 
495
 
427
496
//----------------------------------------------------------------------------
428
497
// ProxyManager
429
498
//----------------------------------------------------------------------------
430
499
class ProxyManager::Private
431
500
{
432
501
public:
433
 
        Private() {}
 
502
        Private() : po(0) {}
434
503
 
435
504
        QPointer<ProxyDlg> pd;
436
505
        QList<int> prevMap;
437
506
        QString lastEdited;
438
507
        OptionsTree *o;
 
508
        ProxyForObject* po;
439
509
        
440
510
        void itemToOptions(ProxyItem pi) {
441
511
                QString base = "proxies." + pi.id;
445
515
        }
446
516
};
447
517
 
448
 
ProxyManager::ProxyManager(OptionsTree *opt, QObject *parent)
449
 
                : QObject(parent)
 
518
ProxyManager::ProxyManager()
 
519
                : QObject(0)
450
520
{
451
521
        d = new Private;
452
 
        d->o = opt;
 
522
}
 
523
 
 
524
void ProxyManager::init(OptionsTree *o)
 
525
{
 
526
        d->o = o;
 
527
        delete d->po;
 
528
        d->po = new ProxyForObject(o, this);
453
529
}
454
530
 
455
531
ProxyManager::~ProxyManager()
457
533
        delete d;
458
534
}
459
535
 
 
536
ProxyManager* ProxyManager::instance()
 
537
{
 
538
        if(!instance_)
 
539
                instance_ = new ProxyManager();
 
540
        return instance_;
 
541
}
 
542
 
460
543
ProxyChooser *ProxyManager::createProxyChooser(QWidget *parent)
461
544
{
462
545
        return new ProxyChooser(this, parent);
541
624
        settingsChanged();
542
625
}
543
626
 
 
627
ProxyItem ProxyManager::getItemForObject(const QString& obj)
 
628
{
 
629
        QString str = obj;
 
630
        return getItem(d->po->itemForObject(str.replace(QRegExp("\\s+"), "_")));
 
631
}
 
632
 
 
633
ProxyForObject* ProxyManager::proxyForObject()
 
634
{
 
635
        return d->po;
 
636
}
 
637
 
 
638
ProxyManager* ProxyManager::instance_ = NULL;
 
639
 
544
640
#include "proxy.moc"