Skip to content

Commit

Permalink
Moved app functionality to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Nov 20, 2024
1 parent e5a682f commit e06bef4
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package/*.tar.*
*~
*.bak
*.auto
build/
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set( SOURCES
YQPackageSelectorHelp.cc
YQPatternSelector.cc

YQPkgApplication.cc
YQPkgChangeLogView.cc
YQPkgChangesDialog.cc
YQPkgClassFilterView.cc
Expand Down
9 changes: 2 additions & 7 deletions src/YQPackageSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ YQPackageSelector::YQPackageSelector( QWidget * parent,
_excludeDevelPkgs = 0;
_excludeDebugInfoPkgs = 0;

// VERSION is a command-line #define (-DVERSION="1.2.3") added
// to the compiler command line by cmake from ../../VERSION.cmake
logInfo() << "This is libyui-qt-pkg " << VERSION << endl;
logDebug() << "Creating YQPackageSelectorBase..." << endl;

if ( onlineUpdateMode() ) logInfo() << "Online update mode" << endl;
if ( updateMode() ) logInfo() << "Update mode" << endl;
Expand Down Expand Up @@ -254,8 +252,6 @@ YQPackageSelector::YQPackageSelector( QWidget * parent,
if ( _filters->diskUsageList() )
_filters->diskUsageList()->updateDiskUsage();

logInfo() << "PackageSelector init done" << endl;


#if CHECK_DEPENDENCIES_ON_STARTUP

Expand All @@ -268,6 +264,7 @@ YQPackageSelector::YQPackageSelector( QWidget * parent,
}
#endif

logDebug() << "YQPackageSelectorBase init done" << endl;
}


Expand Down Expand Up @@ -1883,5 +1880,3 @@ void YQPackageSelector::normalCursor()
{
::normalCursor();
}


65 changes: 65 additions & 0 deletions src/YQPkgApplication.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* File name: YQPkgApplication.h
* Summary: Application class for yqpkg
* License: GPL V2 - See file LICENSE for details.
* Copyright (c) 2024 SUSE LLC
*
* Author: Stefan Hundhammer <[email protected]>
*/


#include <QApplication>

#include "YQPackageSelector.h"
#include "YQPkgApplication.h"
#include "Logger.h"
#include "Exception.h"


YQPkgApplication * YQPkgApplication::_instance = 0;


YQPkgApplication::YQPkgApplication()
: QObject()
, _pkgSel(0)
{
_instance = this;
logDebug() << "Creating YQPkgApplication" << endl;
}


YQPkgApplication::~YQPkgApplication()
{
logDebug() << "Destroying YQPkgApplication..." << endl;

if ( _pkgSel )
{
delete _pkgSel;
_pkgSel = 0;
}

logDebug() << "Destroying YQPkgApplication done" << endl;
_instance = 0;
}


void YQPkgApplication::run()
{
createPkgSel();
qApp->exec();
}


void YQPkgApplication::createPkgSel()
{
if ( _pkgSel )
return;

_pkgSel = new YQPackageSelector( 0, 0 );
CHECK_PTR( _pkgSel );

QObject::connect( _pkgSel, SIGNAL( commit() ),
qApp, SLOT ( quit() ) );

_pkgSel->show();
}
68 changes: 68 additions & 0 deletions src/YQPkgApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* File name: YQPkgApplication.h
* Summary: Application class for yqpkg
* License: GPL V2 - See file LICENSE for details.
* Copyright (c) 2024 SUSE LLC
*
* Author: Stefan Hundhammer <[email protected]>
*/


#ifndef YQPkgApplication_h
#define YQPkgApplication_h

#include <QObject>


class YQPackageSelector;

/**
* Application class for yqpkg.
**/
class YQPkgApplication: public QObject
{
Q_OBJECT

public:
/**
* Constructor
**/
YQPkgApplication();

/**
* Destructor
**/
virtual ~YQPkgApplication();

/**
* Return the instance of this class or 0 if there is none.
*
* This is not a real singleton, but for the life time of this application
* this instance will remain alive, i.e. for most other classes related to
* this.
**/
static YQPkgApplication * instance() { return _instance; }

/**
* Run the application. This also handles the Qt event loop.
**/
void run();

protected:

/**
* Create (and show) the YQPackageSelector if it doesn't already exist.
**/
void createPkgSel();


//
// Data members
//

YQPackageSelector * _pkgSel;

static YQPkgApplication * _instance;
};

#endif // YQPkgApplication_h
24 changes: 10 additions & 14 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <QApplication>
#include <QObject>
#include "YQPackageSelector.h"
#include "YQPkgApplication.h"
#include "Logger.h"
#include "Exception.h"

Expand All @@ -37,23 +37,19 @@ int main( int argc, char *argv[] )
logVersion();

// Set org/app name for QSettings
QCoreApplication::setOrganizationName( "openSUSE" );
QCoreApplication::setApplicationName ( progName );
QCoreApplication::setOrganizationName( "openSUSE" ); // ~/.cache/openSUSE
QCoreApplication::setApplicationName ( progName ); // ~/.cache/openSUSE/yqpkg

QApplication qtApp( argc, argv);
QStringList argList = QCoreApplication::arguments();
argList.removeFirst(); // Remove program name
QApplication qtApp( argc, argv);

QWidget * mainWin = new YQPackageSelector( 0, 0 );
CHECK_PTR( mainWin );
mainWin->show();
{
// New scope to limit the life time of this instance

QObject::connect( mainWin, SIGNAL( commit() ),
&qtApp, SLOT ( quit() ) );
YQPkgApplication app;
app.run();
}

qtApp.exec();

delete mainWin;
logDebug() << "YQPkgApplication finished" << endl;

return 0;
}

0 comments on commit e06bef4

Please sign in to comment.