~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to setting/panelwidget.cpp

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <QDoubleSpinBox>
24
24
#include <QRadioButton>
25
25
#include <QHBoxLayout>
26
 
#include "../dbusproxy/youkersessiondbus.h"
27
26
 
28
 
PanelWidget::PanelWidget(QWidget *parent, SessionDispatcher *proxy, QString cur_desktop, bool has_battery) :
29
 
    QWidget(parent),desktop(cur_desktop),
30
 
    sessionproxy(proxy)
 
27
PanelWidget::PanelWidget(QWidget *parent, QString cur_desktop, bool has_battery) :
 
28
    SettingModulePage(parent),desktop(cur_desktop)
31
29
{
32
 
    dataOK = false;
33
30
    blur_label = new QLabel();
34
31
    transparency_label = new QLabel();
35
32
    date_format_label = new QLabel();
225
222
//    main_layout->setSpacing(0);
226
223
//    main_layout->setContentsMargins(0, 0, 0, 0);
227
224
//    setLayout(main_layout);
228
 
//    this->initData();
 
225
//    this->initSettingData();
229
226
    this->setLanguage();
230
227
}
231
228
 
345
342
    }
346
343
}
347
344
 
 
345
QString PanelWidget::settingModuleName()
 
346
{
 
347
    return "PanelPage";
 
348
}
 
349
 
348
350
void PanelWidget::setLanguage() {
349
351
//    title_label->setText(tr("Dash & Panel"));
350
352
//    description_label->setText(tr("Manage Dash and Panel menu settings."));
369
371
    show_places_label->setText(tr("Show places") + ":");
370
372
}
371
373
 
372
 
bool PanelWidget::getStatus()
373
 
{
374
 
    return this->dataOK;
375
 
}
376
 
 
377
 
void PanelWidget::initData()
 
374
void PanelWidget::initSettingData()
378
375
{
379
376
    if(this->desktop == "mate" || this->desktop == "MATE" || this->desktop == "UKUI" || this->desktop == "ukui") {
380
 
        app_switcher->switchedOn = sessionproxy->get_show_apps_qt();
381
 
        desktop_switcher->switchedOn = sessionproxy->get_show_desktop_qt();
382
 
        icon_switcher->switchedOn = sessionproxy->get_show_icon_qt();
383
 
        places_switcher->switchedOn = sessionproxy->get_show_places_qt();
 
377
        emit this->requestMateOrUnityPanelData(true);
 
378
 
 
379
//        app_switcher->switchedOn = sessionproxy->get_show_apps_qt();
 
380
//        desktop_switcher->switchedOn = sessionproxy->get_show_desktop_qt();
 
381
//        icon_switcher->switchedOn = sessionproxy->get_show_icon_qt();
 
382
//        places_switcher->switchedOn = sessionproxy->get_show_places_qt();
384
383
    }
385
384
    else {//unity
386
 
        int default_value = sessionproxy->get_dash_blur_experimental_qt();
 
385
        emit this->requestMateOrUnityPanelData(false);
 
386
 
 
387
        /*int default_value = sessionproxy->get_dash_blur_experimental_qt();
387
388
        if(default_value == 2) {
388
389
            smart_radio->setChecked(true);
389
390
            static_radio->setChecked(false);
419
420
        date_switcher->switchedOn = sessionproxy->get_show_date_qt();
420
421
 
421
422
        QString cur_power = sessionproxy->get_power_icon_policy_qt();
422
 
        /*QStringList */powerlist  = sessionproxy->get_all_power_icon_policy_qt();
 
423
        m_powerlist  = sessionproxy->get_all_power_icon_policy_qt();
423
424
        battery_combo->clear();
424
425
        battery_combo->clearEditText();
425
 
        battery_combo->addItems(powerlist);
426
 
        QList<QString>::Iterator ite = powerlist.begin(), iteend = powerlist.end();
 
426
        battery_combo->addItems(m_powerlist);
 
427
        QList<QString>::Iterator ite = m_powerlist.begin(), iteend = m_powerlist.end();
427
428
        int index = 0;
428
429
        for(;ite != iteend; ite++,index++)
429
430
        {
433
434
        battery_combo->setCurrentIndex(index);
434
435
 
435
436
        battery_percentage_switcher->switchedOn = sessionproxy->get_show_power_percentage_qt();
436
 
        battery_time_switcher->switchedOn = sessionproxy->get_show_power_time_qt();
 
437
        battery_time_switcher->switchedOn = sessionproxy->get_show_power_time_qt();*/
437
438
    }
438
439
 
439
 
    dataOK = true;
 
440
 
440
441
    this->initConnect();
441
442
}
442
443
 
 
444
void PanelWidget::onSendMatePanelValue(bool app, bool desktop, bool icon, bool places)
 
445
{
 
446
    app_switcher->switchedOn = app;
 
447
    desktop_switcher->switchedOn = desktop;
 
448
    icon_switcher->switchedOn = icon;
 
449
    places_switcher->switchedOn = places;
 
450
}
 
451
 
 
452
void PanelWidget::onSendUnityBlurAndTransparencyValue(int blur, double transparent)
 
453
{
 
454
    if(blur == 2) {
 
455
        smart_radio->setChecked(true);
 
456
        static_radio->setChecked(false);
 
457
        clear_radio->setChecked(false);
 
458
    }
 
459
    else if(blur == 1) {
 
460
        static_radio->setChecked(true);
 
461
        smart_radio->setChecked(false);
 
462
        clear_radio->setChecked(false);
 
463
    }
 
464
    else if(blur == 0) {
 
465
        clear_radio->setChecked(true);
 
466
        static_radio->setChecked(false);
 
467
        smart_radio->setChecked(false);
 
468
    }
 
469
    transparency_slider->setValue(transparent);
 
470
}
 
471
 
 
472
void PanelWidget::onSendUnityTimeValue(const QString &time_format, const QStringList &timelist, bool showSecond, bool showWeek, bool showDate)
 
473
{
 
474
    QStringList m_timelist = timelist;
 
475
    date_combo->clear();
 
476
    date_combo->clearEditText();
 
477
    date_combo->addItems(m_timelist);
 
478
    QList<QString>::Iterator it = m_timelist.begin(), itend = m_timelist.end();
 
479
    int initIndex = 0;
 
480
    for(;it != itend; it++,initIndex++)
 
481
    {
 
482
        if(*it == time_format)
 
483
            break;
 
484
    }
 
485
    date_combo->setCurrentIndex(initIndex);
 
486
 
 
487
    second_switcher->switchedOn = showSecond;
 
488
    week_switcher->switchedOn = showWeek;
 
489
    date_switcher->switchedOn = showDate;
 
490
}
 
491
 
 
492
void PanelWidget::onSendUnityPanelPowerValue(const QString &cur_power, const QStringList &powerlist, bool showPower, bool showBatteryTime)
 
493
{
 
494
    m_powerlist.clear();
 
495
    m_powerlist = powerlist;
 
496
    battery_combo->clear();
 
497
    battery_combo->clearEditText();
 
498
    battery_combo->addItems(m_powerlist);
 
499
    QList<QString>::Iterator ite = m_powerlist.begin(), iteend = m_powerlist.end();
 
500
    int index = 0;
 
501
    for(;ite != iteend; ite++,index++)
 
502
    {
 
503
        if(*ite == cur_power)
 
504
            break;
 
505
    }
 
506
    battery_combo->setCurrentIndex(index);
 
507
 
 
508
    battery_percentage_switcher->switchedOn = showPower;
 
509
    battery_time_switcher->switchedOn = showBatteryTime;
 
510
}
 
511
 
443
512
void PanelWidget::initConnect() {
444
513
//    connect(back_btn, SIGNAL(clicked()), this, SIGNAL(showSettingMainWidget()));
445
 
    connect(smart_radio, SIGNAL(clicked(/*bool*/)), this, SLOT(setRadioButtonRowStatus(/*bool*/)));
446
 
    connect(static_radio, SIGNAL(clicked(/*bool*/)), this, SLOT(setRadioButtonRowStatus(/*bool*/)));
447
 
    connect(clear_radio, SIGNAL(clicked(/*bool*/)), this, SLOT(setRadioButtonRowStatus(/*bool*/)));
 
514
    connect(smart_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
 
515
    connect(static_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
 
516
    connect(clear_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
448
517
    connect(transparency_slider, SIGNAL(valueChanged(double)), this, SLOT(setTransparencyValue(double)));
449
518
    connect(date_combo, SIGNAL(currentIndexChanged(QString)),  this, SLOT(setDateFormat(QString)));
450
519
    connect(second_switcher, SIGNAL(clicked()),  this, SLOT(setDisplaySeconds()));
458
527
    connect(icon_switcher, SIGNAL(clicked()),  this, SLOT(showIcon()));
459
528
    connect(places_switcher, SIGNAL(clicked()),  this, SLOT(showPlaces()));
460
529
 
461
 
    connect(sessionproxy, SIGNAL(string_value_notify(QString, QString)), this, SLOT(panelwidget_notify_string(QString, QString)));
462
 
    connect(sessionproxy, SIGNAL(bool_value_notify(QString, bool)), this, SLOT(panelwidget_notify_bool(QString, bool)));
 
530
//    connect(sessionproxy, SIGNAL(string_value_notify(QString, QString)), this, SLOT(panelwidget_notify_string(QString, QString)));
 
531
//    connect(sessionproxy, SIGNAL(bool_value_notify(QString, bool)), this, SLOT(panelwidget_notify_bool(QString, bool)));
463
532
}
464
533
 
465
534
void PanelWidget::panelwidget_notify_string(QString key, QString value)
466
535
{
467
536
    if (key == "icon-policy") {
468
 
        QList<QString>::Iterator it = powerlist.begin(), itend = powerlist.end();
 
537
        QList<QString>::Iterator it = m_powerlist.begin(), itend = m_powerlist.end();
469
538
        int index = -1;
470
539
        bool exist = false;
471
540
        for(;it != itend; it++)
518
587
 
519
588
void PanelWidget::setTransparencyValue(double value)
520
589
{
521
 
    sessionproxy->set_panel_transparency_qt(value);
 
590
    emit resetPanelTransparencyValue(value);
 
591
//    sessionproxy->set_panel_transparency_qt(value);
522
592
}
523
593
 
 
594
 
 
595
 
524
596
void PanelWidget::setDateFormat(QString selected) {
525
 
    sessionproxy->set_time_format_qt(selected);
 
597
    emit resetDateFormat(selected);
 
598
//    sessionproxy->set_time_format_qt(selected);
526
599
}
527
600
 
528
601
void PanelWidget::setShowBatteryIcon(QString selected) {
529
 
    sessionproxy->set_power_icon_policy_qt(selected);
 
602
    emit resetShowBatteryIcon(selected);
 
603
//    sessionproxy->set_power_icon_policy_qt(selected);
530
604
}
531
605
 
 
606
 
 
607
//TODO: 设计一个枚举变量作为标记,用一个函数去调用dbus设置各个值
532
608
void PanelWidget::setRadioButtonRowStatus(/*bool status*/)
533
609
{
534
610
    QObject *obj = sender(); //返回发出信号的对象,用QObject类型接收
536
612
    QString obj_name = pbtn->objectName();
537
613
    if(obj_name == "smart_radio")
538
614
    {
539
 
        sessionproxy->set_dash_blur_experimental_qt(2);
 
615
        emit resetDashBlurExperimental(2);
 
616
//        sessionproxy->set_dash_blur_experimental_qt(2);
540
617
    }
541
618
    else if(obj_name == "static_radio")
542
619
    {
543
 
        sessionproxy->set_dash_blur_experimental_qt(1);
 
620
        emit resetDashBlurExperimental(1);
 
621
//        sessionproxy->set_dash_blur_experimental_qt(1);
544
622
    }
545
623
    else if(obj_name == "clear_radio")
546
624
    {
547
 
        sessionproxy->set_dash_blur_experimental_qt(0);
 
625
        emit resetDashBlurExperimental(0);
 
626
//        sessionproxy->set_dash_blur_experimental_qt(0);
548
627
    }
549
628
}
550
629
 
551
630
void PanelWidget::setDisplaySeconds()
552
631
{
553
 
    sessionproxy->set_show_seconds_qt(second_switcher->switchedOn);
 
632
    emit resetDisplaySeconds(second_switcher->switchedOn);
 
633
//    sessionproxy->set_show_seconds_qt(second_switcher->switchedOn);
554
634
}
555
635
 
556
636
void PanelWidget::setDisplayWeek()
557
637
{
558
 
    sessionproxy->set_show_week_qt(week_switcher->switchedOn);
 
638
    emit resetDisplayWeek(week_switcher->switchedOn);
 
639
//    sessionproxy->set_show_week_qt(week_switcher->switchedOn);
559
640
}
560
641
 
561
642
void PanelWidget::setDisplayDate()
562
643
{
563
 
    sessionproxy->set_show_date_qt(date_switcher->switchedOn);
 
644
    emit resetDisplayDate(date_switcher->switchedOn);
 
645
//    sessionproxy->set_show_date_qt(date_switcher->switchedOn);
564
646
}
565
647
 
566
648
void PanelWidget::setDisplayBatteryPercentage()
567
649
{
568
 
    sessionproxy->set_show_power_percentage_qt(battery_percentage_switcher->switchedOn);
 
650
    emit resetDisplayBatteryPercentage(battery_percentage_switcher->switchedOn);
 
651
//    sessionproxy->set_show_power_percentage_qt(battery_percentage_switcher->switchedOn);
569
652
}
570
653
 
571
654
void PanelWidget::setDisplayBatteryTime()
572
655
{
573
 
    sessionproxy->set_show_power_time_qt(battery_time_switcher->switchedOn);
 
656
    emit resetDisplayBatteryTime(battery_time_switcher->switchedOn);
 
657
//    sessionproxy->set_show_power_time_qt(battery_time_switcher->switchedOn);
574
658
}
575
659
 
576
660
void PanelWidget::showApplications()
577
661
{
578
 
    sessionproxy->set_show_apps_qt(app_switcher->switchedOn);
 
662
    emit resetShowApplications(app_switcher->switchedOn);
 
663
//    sessionproxy->set_show_apps_qt(app_switcher->switchedOn);
579
664
}
580
665
 
581
666
void PanelWidget::showDesktop()
582
667
{
583
 
    sessionproxy->set_show_desktop_qt(desktop_switcher->switchedOn);
 
668
    emit resetShowDesktop(desktop_switcher->switchedOn);
 
669
//    sessionproxy->set_show_desktop_qt(desktop_switcher->switchedOn);
584
670
}
585
671
 
586
672
void PanelWidget::showIcon()
587
673
{
588
 
    sessionproxy->set_show_icon_qt(icon_switcher->switchedOn);
 
674
    emit resetShowIcon(icon_switcher->switchedOn);
 
675
//    sessionproxy->set_show_icon_qt(icon_switcher->switchedOn);
589
676
}
590
677
 
591
678
void PanelWidget::showPlaces()
592
679
{
593
 
    sessionproxy->set_show_places_qt(places_switcher->switchedOn);
 
680
    emit resetShowPlaces(places_switcher->switchedOn);
 
681
//    sessionproxy->set_show_places_qt(places_switcher->switchedOn);
594
682
}