Skip to content
Snippets Groups Projects
Select Git revision
  • 2fde81db52e4c6efc1d2e101cb9c3217378dbe9c
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • release/201811
  • release/201808
  • releases/beta1
  • packaging
  • native
  • release-0.2.x
  • 1.0.0
  • 0.2.0
  • 0.1.1
  • 0.1.0
25 results

currentaccountwidget.cpp

Blame
    • Anthony Léonard's avatar
      2fde81db
      code cleanup in multiple files · 2fde81db
      Anthony Léonard authored
      Last changes were merged quickly without strict code-review
      as it was needed to integrate them promptly.
      Related modifications:
       * callwidget.cpp: Removed unnecessary line feed
       * callwidget.{cpp,ui}: Renamed “contactRequestView” to
         “contactRequestPage” for consistency
       * contactrequestwidget.cpp: Refactoring of a too-long line
       * sendcontactrequestwidget.{cpp,ui}: Better placeholders
      
      Moreover, contactrequestwidget.{cpp,ui} were missing the GPL
      header and copyrights' years are now updated to 2017 in every
      files.
      
      Change-Id: Id52f340fc62340df6cf5bda8d782fefc732beabe
      2fde81db
      History
      code cleanup in multiple files
      Anthony Léonard authored
      Last changes were merged quickly without strict code-review
      as it was needed to integrate them promptly.
      Related modifications:
       * callwidget.cpp: Removed unnecessary line feed
       * callwidget.{cpp,ui}: Renamed “contactRequestView” to
         “contactRequestPage” for consistency
       * contactrequestwidget.cpp: Refactoring of a too-long line
       * sendcontactrequestwidget.{cpp,ui}: Better placeholders
      
      Moreover, contactrequestwidget.{cpp,ui} were missing the GPL
      header and copyrights' years are now updated to 2017 in every
      files.
      
      Change-Id: Id52f340fc62340df6cf5bda8d782fefc732beabe
    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
        }
    }