Skip to content
Snippets Groups Projects
Select Git revision
  • a775bea90282c32292b4be3a9502b32eca24fefe
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/releaseWindowsTestOne
  • release/windowsReleaseTest
  • release/releaseTest
  • release/releaseWindowsTest
  • release/201910
  • release/qt/201910
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • 4.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.1
  • 2.0.0
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.0
31 results

codec.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    currentaccountwidget.cpp 4.79 KiB
    /***************************************************************************
     * Copyright (C) 2015-2017 by Savoir-faire Linux                           *
     * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>          *
     * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>          *
     *                                                                         *
     * 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 "currentaccountwidget.h"
    #include "ui_currentaccountwidget.h"
    #include "globalinstances.h"
    #include "accountmodel.h"
    #include "account.h"
    #include "qstandarditemmodel.h"
    #include "profilemodel.h"
    #include "profile.h"
    #include "person.h"
    #include "utils.h"
    
    
    CurrentAccountWidget::CurrentAccountWidget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::CurrentAccountWidget)
    {
        ui->setupUi(this);
        setup();
    }
    
    CurrentAccountWidget::~CurrentAccountWidget()
    {
        delete ui;
    }
    
    void
    CurrentAccountWidget::setup()
    {
        ui->accountsStatus->setText("No enabled account: impossible to communicate!");
        ui->accountsStatus->hide();
        updateAccounts();
        if (ui->currentAccountSelector->count() > 0) {
            ui->currentAccountSelector->setCurrentIndex(0);
            emit ui->currentAccountSelector->currentIndexChanged(0);
            qDebug() << "CurrentAccount : setup over";
        } else {
            qDebug() << "CurrentAccount : No account available";
        }
    }
    
    void
    CurrentAccountWidget::update()
    {
        updateAccounts();
    
    }
    
    void
    CurrentAccountWidget::updateAccounts()
    {
        auto selector = ui->currentAccountSelector;
        AccountModel* model = &(AccountModel::instance());
        QModelIndex qIndex;
    
        selector->clear();
    
        for (int idx = 0; idx <=  model->rowCount() - 1; idx++){
            qIndex = model->index(idx);
            if (! model->getAccountByModelIndex(qIndex)->isEnabled()) {
                qDebug() << model->getAccountByModelIndex(qIndex)->alias() << " Account is not enabled";
            } else {
                selector->addItem(model->getAccountByModelIndex(qIndex)->alias());
            }
        }
    
        if (selector->count() <= 1){
            selector->hide();
            if (selector->count() < 1) {
                ui->accountsStatus->show();
                setPhoto();
            } else {
                ui->accountsStatus->hide();
            }
        } else {
            selector->show();
            ui->accountsStatus->hide();
        }
    }
    
    
    
    void
    CurrentAccountWidget::setPhoto()
    {
        auto selector = ui->currentAccountSelector;
        if (selector->count() > 0) {
            if(&ProfileModel::instance()){
                if (ProfileModel::instance().selectedProfile()) {
                    if (ProfileModel::instance().selectedProfile()->person()){
                        QImage img = Utils::getCirclePhoto(ProfileModel::instance().selectedProfile()->person()->photo().value<QImage>(),
                                                           ui->idDisplayLayout->contentsRect().height());
                        ui->currentAccountPixmap->setPixmap(QPixmap::fromImage(img));
                        qDebug() << "CurrentAccount : Photo set";
                    } else {
                        qDebug() << "CurrentAccount : selected profile has no person";
                    }
                } else {
                    qDebug() << "CurrentAccount : Profilemodel: no selected profile";
                }
            } else {
                qDebug() << "CurrentAccount : Profilemodel not set";
            }
        } else {
            qDebug() << "CurrentAccount : account not set";
            ui->currentAccountPixmap->setPixmap(QPixmap());
        }
    }
    
    void
    CurrentAccountWidget::on_currentAccountSelector_currentIndexChanged(int index)
    {
        QModelIndex idx = ui->currentAccountSelector->model()->index(index,0);
        Account* ac = AccountModel::instance().getAccountByModelIndex(idx);
    
        if (ac) {
            AccountModel::instance().setUserChosenAccount(ac);
            setPhoto();
        } else {
            qDebug() << "CurrentAccount : account not referenced correctly";
            //null for now
        }
    }