QtPass Developer documentation
QtPass test coverage
Current view: top level - src/passbackendfactory.cpp (source / functions) Coverage Total Hit
Test: QtPass Lines: 96.3 % 27 26
Test Date: 2026-12-03 23:34:20 Functions: 100.0 % 5 5
Branches: 87.0 % 23 20

             Branch data     Line data    Source code
       1                 :             : // SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
       2                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       3                 :             : /**
       4                 :             :  * @file
       5                 :             :  * @brief Implements PassBackendFactory. The backends are held through
       6                 :             :  * pointers and constructed on first use, so nothing depends on the
       7                 :             :  * initialisation order of globals.
       8                 :             :  */
       9                 :             : 
      10                 :             : #include "passbackendfactory.h"
      11                 :             : #include "appsettings.h"
      12                 :             : #include "pass.h"
      13                 :             : #include "qtpasssettings.h"
      14                 :             : #include "util.h"
      15                 :             : 
      16                 :             : #include <QDebug>
      17                 :             : #include <QDir>
      18                 :             : 
      19                 :             : Pass *PassBackendFactory::pass = nullptr;
      20                 :             : QScopedPointer<RealPass> PassBackendFactory::realPass;
      21                 :             : QScopedPointer<ImitatePass> PassBackendFactory::imitatePass;
      22                 :             : 
      23                 :         860 : auto PassBackendFactory::getPass() -> Pass * {
      24         [ +  + ]:         860 :   if (!pass) {
      25                 :             :     // With the active profile's Git flags: what the backend runs with.
      26                 :         294 :     AppSettings s = QtPassSettings::loadEffective();
      27                 :             :     // Ensure store directory exists (first-run side effect — load() normalises
      28                 :             :     // the path but does not create the directory).
      29   [ +  +  +  +  :         588 :     if (!QDir(s.passStore).exists() && !Util::mkpathForStore(s.passStore)) {
             +  +  -  -  
                      + ]
      30                 :           0 :       qWarning() << "Failed to create password store directory:" << s.passStore;
      31                 :             :     }
      32         [ +  + ]:         294 :     if (s.usePass) {
      33                 :           6 :       pass = getRealPass();
      34                 :             :     } else {
      35                 :         288 :       pass = getImitatePass();
      36                 :             :     }
      37         [ +  - ]:         294 :     if (pass) {
      38                 :         294 :       pass->init(s);
      39                 :             :     }
      40                 :         294 :   }
      41                 :         860 :   return pass;
      42                 :             : }
      43                 :             : 
      44                 :         475 : auto PassBackendFactory::getRealPass() -> RealPass * {
      45         [ +  + ]:         475 :   if (realPass.isNull()) {
      46                 :           6 :     realPass.reset(new RealPass());
      47                 :             :   }
      48                 :         475 :   return realPass.data();
      49                 :             : }
      50                 :             : 
      51                 :         953 : auto PassBackendFactory::getImitatePass() -> ImitatePass * {
      52         [ +  + ]:         953 :   if (imitatePass.isNull()) {
      53                 :           6 :     imitatePass.reset(new ImitatePass());
      54                 :           6 :     AppSettings s = QtPassSettings::loadEffective();
      55                 :           6 :     imitatePass->init(s);
      56                 :           6 :   }
      57                 :         953 :   return imitatePass.data();
      58                 :             : }
      59                 :             : 
      60                 :         421 : auto PassBackendFactory::isIdle() -> bool {
      61   [ +  +  +  + ]:         738 :   return (realPass.isNull() || realPass->isIdle()) &&
      62                 :         421 :          (imitatePass.isNull() || imitatePass->isIdle());
      63                 :             : }
      64                 :             : 
      65                 :        1249 : void PassBackendFactory::invalidate() { pass = nullptr; }
        

Generated by: LCOV version 2.0-1