Skip to content

Commit

Permalink
Merge pull request #73 from shalomRachapudi/OCICallbacks
Browse files Browse the repository at this point in the history
One Click Installer Callbacks
  • Loading branch information
antlarr committed Aug 22, 2016
2 parents f595403 + ffb5914 commit a26c1da
Show file tree
Hide file tree
Showing 14 changed files with 1,253 additions and 180 deletions.
10 changes: 7 additions & 3 deletions src/CMakeLists.txt
Expand Up @@ -16,6 +16,7 @@ include_directories(${Qt5DBus_INCLUDES})
set(Qt5_USE_DBUS, true)

find_package(PACKAGEKITQT5 REQUIRED)
find_package(KF5WidgetsAddons REQUIRED)
find_package(KF5I18n NO_MODULE)

#We need -DQT_WIDGETS_LIB when using QtWidgets in Qt5
Expand All @@ -25,8 +26,8 @@ add_definitions(${Qt5DBus_DEFINITIONS})
set(oneclickinstaller_SOURCES main.cpp backendoci.cpp conflictresolutionscreen.cpp utils.cpp mainwindow.cpp firstscreen.cpp settings.cpp fakebackend.cpp repository.cpp package.cpp ympparser.cpp packagebackend.cpp installscreen.cpp repositorywidget.cpp summary.cpp keyringcallbacks.cpp mainheader.cpp packagedetails.cpp repositorymetadata.cpp repositorydata.cpp packagemetadata.cpp zyppinfo.cpp)
set(oneclickinstaller_HEADERS backendoci.h conflictresolutionscreen.h utils.h mainwindow.h checkconflictscreen.h firstscreen.h settings.h installscreen.h repositorywidget.h summary.h mainheader.h packagedetails.h packagemetadata.h packagebackend.h zyppinfo.h)

set(oneclickhelper_SOURCES interfacemain.cpp backend.cpp utils.cpp zyppinstall.cpp)
set(oneclickhelper_HEADERS backend.h keyring.h utils.h zyppinstall.h)
set(oneclickhelper_SOURCES interfacemain.cpp backend.cpp utils.cpp zyppinstall.cpp media.cpp callbacks.cpp)
set(oneclickhelper_HEADERS backend.h keyring.h utils.h zyppinstall.h media.h callbacks.h runtimedata.h)

QT5_WRAP_CPP(oneclickhelper_HEADERS_MOC ${oneclickhelper_HEADERS})
QT5_WRAP_CPP(oneclickinstaller_HEADERS_MOC ${oneclickinstaller_HEADERS})
Expand All @@ -36,11 +37,14 @@ set(srcs_DBUS_OCIHelper org.opensuse.OCIHelper.xml)
set(srcs_DBUS_OCI org.opensuse.oneclickinstaller.xml)
qt5_add_dbus_interface(prog_iFaceHelper org.opensuse.OCIHelper.xml oci_helper_interface)
qt5_add_dbus_interface(prog_iFaceOCI org.opensuse.oneclickinstaller.xml oci_interface)
qt5_add_dbus_interface(prog_iFaceHelper org.opensuse.mediacallbacks.xml media_callbacks_interface)

qt5_add_dbus_adaptor(srcs_DBUS_OCIHelper org.opensuse.OCIHelper.xml backend.h Backend)
qt5_add_dbus_adaptor(srcs_DBUS_OCIHelper org.opensuse.mediacallbacks.xml callbacks.h Callbacks)
qt5_add_dbus_adaptor(srcs_DBUS_OCI org.opensuse.oneclickinstaller.xml conflictresolutionscreen.h ConflictResolutionScreen)

qt5_generate_moc(backend.h backend.moc)
qt5_generate_moc(callbacks.h callbacks.moc)
qt5_generate_moc(conflictresolutionscreen.h conflictresolutionscreen.moc)

#Executables fail to build with Qt5 in the default configuration
Expand All @@ -51,7 +55,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_executable(oneclickhelper ${QT_LIBRARIES} ${oneclickhelper_SOURCES} ${prog_iFaceOCI} ${oneclickhelper_HEADERS} ${srcs_DBUS_OCIHelper} ${oneclickhelper_HEADERS_MOC})
add_executable(oneclickinstaller ${QT_LIBRARIES} ${prog_iFaceHelper} ${srcs_DBUS_OCI} ${oneclickinstaller_SOURCES} ${oneclickinstaller_HEADERS} ${oneclickinstaller_HEADERS_MOC})

target_link_libraries(oneclickhelper ${QT_QTGUI_LIBRARY} zypp ${QT_QTDBUS_LIBRARY})
target_link_libraries(oneclickhelper ${QT_QTGUI_LIBRARY} zypp KF5::I18n KF5::WidgetsAddons ${QT_QTDBUS_LIBRARY})
target_link_libraries(oneclickinstaller ${QT_QTGUI_LIBRARY} KF5::I18n zypp ${QT_QTDBUS_LIBRARY} ${PackageKitQt5_LIBRARIES})

INSTALL(TARGETS oneclickhelper DESTINATION /usr/sbin)
Expand Down
58 changes: 58 additions & 0 deletions src/callbacks.cpp
@@ -0,0 +1,58 @@
/***********************************************************************************
* One Click Installer makes it easy for users to install software, no matter
* where that software is located.
*
* Copyright (C) 2016 Shalom <shalomray7@gmail.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/>.
************************************************************************************
* This program's developed as part of GSoC - 2016
* Project: One Click Installer
* Mentors: Antonio Larrosa, and Cornelius Schumacher
* Organization: OpenSUSE
* Previous Contributor: None
***********************************************************************************/

#include "callbacks.h"
#include "mediacallbacksadaptor.h"

Callbacks::Callbacks()
{
new MediaCallbacksAdaptor( this );
QDBusConnection connection = QDBusConnection::systemBus();
if ( !connection.isConnected() ) {
qFatal( "Cannot connect to the D-Bus system bus" );
exit( 1 );
}
connection.registerObject( "/Media", this );
if ( !connection.registerService( "org.opensuse.MediaCallbacks" ) ) {
qDebug() << qPrintable( connection.lastError().message() );
exit( 1 );
}
}

void Callbacks::emitStartResolvable( QString info )
{ emit startResolvable( info ); }

void Callbacks::emitFinishResolvable( QString info, bool success )
{ emit finishResolvable( info, success ); }

void Callbacks::emitStartProgress( QString info )
{ emit startProgress( info ); }

void Callbacks::emitFinishProgress( QString info, bool success )
{ emit finishProgress( info, success ); }

void Callbacks::emitProgress( int value )
{ emit progress( value ); }
24 changes: 24 additions & 0 deletions src/callbacks.h
@@ -0,0 +1,24 @@
#ifndef CALLBACKS_H
#define CALLBACKS_H

#include <QObject>

class Callbacks : public QObject
{
Q_OBJECT
Q_CLASSINFO( "D-Bus Interface", "org.opensuse.MediaCallbacks" )
public:
Callbacks();
void emitStartResolvable( QString info );
void emitFinishResolvable( QString info, bool success );
void emitProgress( int value );
void emitStartProgress( QString );
void emitFinishProgress( QString, bool success );
Q_SIGNALS:
void startProgress( QString );
void finishProgress( QString, bool );
void startResolvable( QString );
void finishResolvable( QString, bool );
void progress( int );
};
#endif
242 changes: 131 additions & 111 deletions src/installscreen.cpp
@@ -1,138 +1,158 @@
// Copyright 2012 Saurabh Sood <saurabh@saurabh.geeko>
//
// 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 2 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
//

/***********************************************************************************
* One Click Installer makes it easy for users to install software, no matter
* where that software is located.
*
* Copyright (C) 2016 Shalom <shalomray7@gmail.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/>.
************************************************************************************
* This program's developed as part of GSoC - 2016
* Project: One Click Installer
* Mentors: Antonio Larrosa, and Cornelius Schumacher
* Organization: OpenSUSE
* Previous Contributor: None
***********************************************************************************/

#include <klocalizedstring.h>
#include <QHBoxLayout>
#include "installscreen.h"

InstallScreen::InstallScreen(PackageBackend *backend, const QString& tmpFileName, QObject *parent )
InstallScreen::InstallScreen()
{
setStyleSheet( "" );
m_backend = backend;
m_tmpFileName = tmpFileName;

m_watcher = new QFileSystemWatcher;
m_watcher->addPath( QString::fromLocal8Bit( "/var/log/oneclick.log" ) );

QObject::connect( m_watcher, SIGNAL( fileChanged( QString ) ), this, SLOT( logFileChanged( QString ) ) );

QWidget *packageWidget = new QWidget;
packageWidget->setObjectName( "packageWidget" );
packageWidget->setStyleSheet( "QWidget#packageWidget{ background-color : white; border-bottom : 1px solid rgb(196,181,147); border-left : 1px solid rgb(196,181,147); border-top : 1px solid rgb(196,181,147); border-right : 1px solid rgb(196,181,147); }" );

QVBoxLayout *mainLayout = new QVBoxLayout;
QVBoxLayout *installLayout = new QVBoxLayout( packageWidget );

QVBoxLayout *sourceLayout = new QVBoxLayout;
QHBoxLayout *buttonLayout = new QHBoxLayout;

m_installStatus = new QLabel( i18n("Downloading and Installing Packages") );
m_cancel = new QPushButton( i18n("Cancel Installation") );

QObject::connect( m_cancel, SIGNAL( clicked() ), this, SLOT( cancelInstallation() ) );

m_mainLayout = new QVBoxLayout;

// log file
m_logFile.setFileName( "/tmp/oci_log.txt" );
if( !m_logFile.open( QIODevice::Truncate | QIODevice::WriteOnly ) ) {
qDebug() << "Could not open Data File";
}
m_outData = new QTextStream( &m_logFile );

// status widget and its layout
m_statusWidget = new QTextBrowser;
m_statusWidget->setObjectName( "statusWidget" );
m_statusWidget->setStyleSheet( "QTextBrowser#statusWidget{ background-color : white; border-bottom: 1px solid rgb(196, 181, 147); border-left : 1px solid rgb(196,181,147); border-top : 1px solid rgb(196,181,147); border-right : 1px solid rgb(196,181,147); }" );
m_statusWidget->setMinimumSize( 500, 180 );

// Cancel button
m_cancelButton = new QPushButton( "Cancel" );
QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->addSpacing( 400 );
buttonLayout->addWidget( m_cancelButton );

// Current message label, Progress Bar
m_currentPackageStatusLabel = new QLabel( "Please Wait..." );
m_progressBar = new QProgressBar;
m_progressBar->setFixedHeight( 20 );
m_progressBar->setMinimum( 0 );
m_progressBar->setMaximum( 100 );
m_progressBar->setRange( 0, 100 );
m_progressBar->setTextVisible( true );

// All set! Now add widgets to the m_mainLayout
m_mainLayout->addWidget( m_statusWidget );
m_mainLayout->setSpacing( 0 );
m_mainLayout->addWidget( horizontalLine() );
m_mainLayout->setSpacing( 0 );
m_mainLayout->addWidget( m_currentPackageStatusLabel );
m_mainLayout->setSpacing( 0 );
m_mainLayout->addWidget( m_progressBar );
m_mainLayout->setSpacing( 0 );
m_mainLayout->addWidget( horizontalLine() );
m_mainLayout->setSpacing( 5 );
m_mainLayout->addLayout( buttonLayout );

// Signals and slots
QObject::connect( m_cancelButton, SIGNAL( clicked() ), this, SLOT( cancelInstallation() ) );

setLayout( m_mainLayout );
}

installLayout->addWidget( m_progressBar );
installLayout->setSpacing( 20 );

foreach( QUrl iter, m_backend->repositories() ) {
QLabel *sourceLabel = new QLabel( i18n("Added Source: %1").arg(iter.toString()) );
sourceLabel->setStyleSheet( "background-color: rgb(254, 250, 210); border-bottom : 1px solid rgb(252,233,79); border-left : 1px solid rgb(196,181,147); border-top : 1px solid rgb(196,181,147); border-right : 1px solid rgb(196,181,147);" );
sourceLayout->addWidget( sourceLabel );
sourceLayout->setSpacing( 0 );
sourceLabel->setFixedHeight( 40 );
// sourceLabel->setContentsMargins( 20, 20, 20, 20 );
void InstallScreen::initDBusServices()
{
m_ociHelper = new org::opensuse::OCIHelper("org.opensuse.OCIHelper", "/", QDBusConnection::systemBus(), this);
if ( !m_ociHelper->isValid() ) {
qFatal( "Oops! Cannot connect to the service org.opensuse.OCIHelper" );
exit( 1 );
}

int i = 0;

foreach( QString iter, m_backend->packages() ) {
QHBoxLayout *packageLayout = new QHBoxLayout;
m_packageLayouts.insert( i, packageLayout );
QLabel *package = new QLabel( i18n("<b>Installing: </b> %1").arg(iter) );
package->setFixedHeight( 40 );
package->setStyleSheet( "background-color : white" );
packageLayout->addWidget( package );
packageLayout->setSpacing( 200 );
installLayout->addLayout( packageLayout );

m_mediaCallbacks = new org::opensuse::MediaCallbacks("org.opensuse.MediaCallbacks", "/Media", QDBusConnection::systemBus(), this);
if ( !m_mediaCallbacks->isValid() ) {
qFatal( "Oops! Cannot connect to the service org.opensuse.MediaCallbacks" );
exit( 1 );
}

buttonLayout->addSpacing( 400 );
buttonLayout->addWidget( m_cancel );
mainLayout->setSpacing( 0 );
mainLayout->addLayout( sourceLayout );
mainLayout->addSpacing( 0 );
mainLayout->addWidget( packageWidget );
mainLayout->addSpacing( 20 );
mainLayout->addLayout( buttonLayout );

setLayout( mainLayout );

qDebug() << " DBus proxies initialized";

// signals and slots
connect( m_mediaCallbacks, SIGNAL( startProgress( QString ) ), this, SLOT( newProgressInAction( QString ) ) );
connect( m_mediaCallbacks, SIGNAL( startResolvable( QString ) ), this, SLOT( newResolvableInAction( QString ) ) );
connect( m_mediaCallbacks, SIGNAL( finishProgress( QString, bool ) ), this, SLOT( updateCurrentProgressStatusUponCompletion( QString, bool ) ) );
connect( m_mediaCallbacks, SIGNAL( finishResolvable( QString, bool ) ), this, SLOT( updateCurrentResolvableStatusUponCompletion( QString, bool ) ) );
connect( m_mediaCallbacks, SIGNAL( progress( int ) ), m_progressBar, SLOT( setValue( int ) ) ); // update progress
}


void InstallScreen::showCompletionStatus()
// Invoke this every time startResolvable() is emitted from start() method[ in media.h ] except for
// DownloadProgressReportReceiver in OCIHelper
void InstallScreen::newResolvableInAction( QString label_R )
{
m_progressBar->hide();

foreach( QHBoxLayout *l, m_packageLayouts ) {
QLabel *completed = new QLabel( i18n("Installed") );
completed->setStyleSheet( "background-color : white" );
l->addWidget( completed );
}
m_statusWidget->append( label_R );
}

void InstallScreen::logFileChanged( const QString& path )
// Invoke this every time finishResolvable() is emitted from finish() method[ in media.h ] except
// DownloadProgressReportReceiver in OCIHelper
void InstallScreen::updateCurrentResolvableStatusUponCompletion( QString finish_R, bool success )
{
qDebug() << "changed";
QFile file( path );
if( file.open( QIODevice::ReadOnly ) ) {
QString str( file.readAll() );

if( str == "" || str.isNull() )
return;
QStringList line = str.split(QRegExp("[\r\n]"),QString::SkipEmptyParts);

QString final = line.last();
qDebug() << final;
QString num = final.split( "=" ).at( 1 );
num.remove( 0, 1 );
num.remove( num.length() - 1, 1 );
int val = num.toInt();
m_statusWidget->append( finish_R );
}

qDebug() << val;
void InstallScreen::newProgressInAction( QString label_R )
{
m_currentPackageStatusLabel->setText( label_R );
// write it to the log file
( *m_outData ) << label_R << "\n";
m_progressBar->reset();
}

m_progressBar->setValue( val );
void InstallScreen::updateCurrentProgressStatusUponCompletion( QString finish_R, bool success )
{
// set the progress bar to 100
m_progressBar->setValue( 100 );
// write it to the log file
( *m_outData ) << finish_R << "\n";
m_currentPackageStatusLabel->setText( finish_R );
}

}
QWidget* InstallScreen::horizontalLine()
{
QWidget* horizontalLine = new QWidget;
horizontalLine->setFixedHeight( 2 );
horizontalLine->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
horizontalLine->setStyleSheet( QString( "background-color: #c0c0c0;" ) );
return horizontalLine;
}

void InstallScreen::cancelInstallation()
{
qDebug() << "cancelling installation";
qDebug() << "cancelling installation";

closeLogFile();
m_ociHelper->killBackend(); // quit OCIHelper
qApp->quit(); // quit OCI
}

// The following feature will be added as development progresses on :)
//ClientDBus *client = new ClientDBus( "org.opensuse.oneclickinstaller", "/", QDBusConnection::sessionBus(), 0 );
//client->KillBackend();
//qApp->quit();
void InstallScreen::closeLogFile()
{
qDebug() << "closing file [ in installscreen ]";
m_logFile.close();
}

0 comments on commit a26c1da

Please sign in to comment.