Permalink
Browse files

Merge branch 'master' of github.com:pcbsd/pcbsd

  • Loading branch information...
2 parents 2ead8ff + 109c737 commit 7fa3570ef055632e497f5282edbbe683e1c4dc32 @kmoore134 kmoore134 committed Mar 5, 2014
View
18 src-qt4/libpcbsd/utils/pcbsd-DLProcess.cpp
@@ -94,26 +94,30 @@ void DLProcess::calculateStats(QString current, QString total, QString speed, QS
percent = -1;
}
//Check if total is known
- if(!totok){
+ if(!totok && curok){
//Only Current is known
tot = cur; //output current instead of total since no percent either
}
//OTHER input (speed, filename)
- QString other;
+ QString other = "??";
//Check the speed
if(!speed.isEmpty()){
spd = speed.toDouble(&spdok);
- if(spdok && spd==0){ spdok=false; }
- if(!spdok){
- spd = -1; //unknown
+ if(spdok && spd<=0){ spdok=false; }
+ if(spdok){
+ other = kbToString(spd)+"/s";
}
- other = kbToString(spd)+"/s";
//Check for a filename instead
}else if(!filename.isEmpty() ){
other = filename;
}
//Now emit the stats
- emit UpdatePercent(QString::number(percent), kbToString(tot), other);
+ QString perc = "??";
+ if(percent >= 0){ perc = QString::number(percent); }
+ QString tota = "??";
+ if(tot >= 0){ tota = kbToString(tot); }
+
+ emit UpdatePercent(perc, tota, other);
}
void DLProcess::parsePBILine(QString line){
View
169 src-qt4/life-preserver/lp-gui/LPClassic.cpp
@@ -0,0 +1,169 @@
+#include "LPClassic.h"
+#include "ui_LPClassic.h"
+
+//====PUBLIC=====
+LPClassic::LPClassic(QWidget *parent) : QDialog(parent), ui(new Ui::LPClassic){
+ ui->setupUi(this); //load the designer file
+ //initialize the file check timer
+ fCheck = new QTimer(this);
+ fCheck->setInterval(2000); //2 second update interval
+ fCheck->setSingleShot(true);
+ connect(fCheck, SIGNAL(timeout()), this, SLOT(updateFCheck()) );
+ //initialize the tar process
+ tarProc = new QProcess(this);
+ tarProc->setProcessEnvironment( QProcessEnvironment::systemEnvironment());
+ connect(tarProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotTarDone()) );
+ //initialize the QFileInfo
+ tarInfo = new QFileInfo();
+ tarInfo->setCaching(false);
+ //set the initial stopped flag
+ stopped = false;
+ running = false;
+ ui->list_exclude->clear(); //make sure the exclude list is cleared (possibly different base-dir)
+ //Make sure the initial state of the UI is correct
+ on_list_exclude_itemSelectionChanged();
+}
+
+LPClassic::~LPClassic(){
+
+}
+
+void LPClassic::setHomeDir(QString home){
+ //Generate the recommended filename
+ tarDir = home.section("/",-1);
+ tarBaseDir = home;
+ tarBaseDir.chop(tarDir.length() +1);
+ ui->line_filename->setText(tarDir+"-"+QDateTime::currentDateTime().toString("yyyyMMdd-hhmm"));
+ //Now set the process to start in the parent directory
+ tarProc->setWorkingDirectory(tarBaseDir);
+ //Now make sure we start on the right page
+ ui->stackedWidget->setCurrentWidget(ui->page_setup);
+}
+
+//====PRIVATE====
+void LPClassic::updateFCheck(){
+ //Get the current size of the file
+ tarInfo->refresh();
+ double size = tarInfo->size();
+ QStringList labels; labels << "B" << "KB" << "MB" << "GB" << "TB" << "PB" << "EB";
+ int i=0;
+ while( size > 1024 && i < labels.length() ){
+ size = size/1024;
+ i++;
+ }
+ //Round to 2 decimel places if GB or larger
+ if(i>2){ size = int(size*100)/100.0; }
+ else{ size = int(size); }
+ //Now display that size
+ ui->label_size->setText( QString::number(size)+" "+labels[i] );
+ if(!stopped){ fCheck->start(); }
+}
+
+void LPClassic::slotTarDone(){
+ running = false;
+ fCheck->stop();
+ updateFCheck(); //Final update for the file size
+ if(stopped){
+ qDebug() << "Home-Dir Package Cancelled";
+ ui->label_status->setText(tr("Cancelled"));
+ //Now try to delete the partial file
+ QString file = tarBaseDir+"/"+tarFile;
+ qDebug() << " - Removing partial archive file:" << file;
+ QFile::remove(file);
+ }else{
+ qDebug() << "Home-Dir Package Finished";
+ ui->label_status->setText(tr("FINISHED"));
+ }
+ ui->push_stop->setVisible(false);
+ ui->push_finished->setVisible(true);
+ //Set the progress bar as finished
+ ui->progressBar->setRange(0,1);
+ ui->progressBar->setValue(1);
+}
+
+//Exclude list controls
+void LPClassic::on_tool_rmexclude_clicked(){
+ delete ui->list_exclude->takeItem( ui->list_exclude->currentRow() );
+}
+
+void LPClassic::on_tool_addexcludefile_clicked(){
+ QStringList paths = QFileDialog::getOpenFileNames(this, tr("Exclude Files"), tarBaseDir+"/"+tarDir, tr("All Files (*)"));
+ for(int i=0; i<paths.length(); i++){
+ if(!paths[i].startsWith(tarBaseDir+"/"+tarDir)){ continue; } //invalid file
+ ui->list_exclude->addItem(paths[i]);
+ }
+}
+
+void LPClassic::on_tool_addexcludedir_clicked(){
+ QString path = QFileDialog::getExistingDirectory(this, tr("Exclude Directory"), tarBaseDir+"/"+tarDir);
+ if(path.isEmpty() || !path.startsWith(tarBaseDir+"/"+tarDir) ){ return; }
+ if(!path.endsWith("/")){ path.append("/"); } //make sure there is a / on the end of directories
+ ui->list_exclude->addItem(path);
+}
+
+void LPClassic::on_list_exclude_itemSelectionChanged(){
+ ui->tool_rmexclude->setEnabled( ui->list_exclude->currentItem() != 0 );
+}
+
+
+//Main Buttons
+void LPClassic::on_push_cancel_clicked(){
+ this->close(); //Just close this window
+}
+
+void LPClassic::on_push_start_clicked(){
+ //Read the UI to create the exclude list
+ stopped = false;
+ running = true;
+ tarFile = ui->line_filename->text()+".home.tar.gz";
+ tarInfo->setFile(tarBaseDir+"/"+tarFile);
+ //Generate the command
+ QStringList args;
+ args << "-czf" << tarBaseDir+"/"+tarFile << "-C" << tarBaseDir << tarDir;
+ //Create the exclude list
+ QStringList excludes;
+ excludes << "*flashplayer*"; //Always exclude the flashplayer library
+ excludes << "*/.zfs/*"; //Always exclude the hidden zfs directoriess
+ if(ui->check_pbidesktop->isChecked()){ excludes << "*/PBI-*.desktop"; } //Don't include PBI entries
+ if(ui->check_userbin->isChecked()){ excludes << "*/bin/*"; } //exclude "bin" directories
+ for( int i=0; i<ui->list_exclude->count(); i++){
+ QString path = ui->list_exclude->item(i)->text();
+ //Remove the base homedir path
+ path.remove(0,tarBaseDir.length()+tarDir.length()+1);
+ if(path.endsWith("/")){ path.append("*"); } //don't put the asterisk on the end of files
+ excludes << "*"+path;
+ }
+ //Now convert the exclude list into additional arguments
+ for(int i=0; i<excludes.length(); i++){
+ args.prepend(excludes[i]); args.prepend("--exclude");
+ }
+ //qDebug() << "Package command:" << "tar" << args;
+ //Start the process
+ tarProc->start("tar",args); //complex command, use args individually
+ tarProc->waitForStarted(1000);
+ //Start the file watcher
+ fCheck->start();
+ //Now show the proper page with correct elements
+ ui->label_fullfilename->setText(tarBaseDir+"/"+tarFile);
+ ui->push_finished->setVisible(false);
+ ui->push_stop->setVisible(true);
+ ui->label_status->setText(tr("Packaging Home Directory...") );
+ ui->progressBar->setRange(0,0);
+ ui->progressBar->setValue(-1);
+ ui->stackedWidget->setCurrentWidget(ui->page_running);
+}
+
+void LPClassic::on_push_stop_clicked(){
+ stopped = true;
+ tarProc->kill();
+ tarProc->waitForFinished(1000); //wait a second to let it die
+ if(tarProc->state() != QProcess::NotRunning){
+ tarProc->terminate(); //force kill it
+ tarProc->waitForFinished(300);
+ }
+}
+
+void LPClassic::on_push_finished_clicked(){
+ this->close(); //Just close this window
+}
+
View
54 src-qt4/life-preserver/lp-gui/LPClassic.h
@@ -0,0 +1,54 @@
+#ifndef _LP_GUI_CLASSIC_BACKUP_H
+#define _LP_GUI_CLASSIC_BACKUP_H
+
+#include <QDialog>
+#include <QTimer>
+#include <QFile>
+#include <QFileInfo>
+#include <QDebug>
+#include <QProcess>
+#include <QProcessEnvironment>
+#include <QDateTime>
+#include <QFileDialog>
+
+namespace Ui{
+ class LPClassic;
+};
+
+class LPClassic : public QDialog{
+ Q_OBJECT
+public:
+ LPClassic(QWidget *parent = 0);
+ ~LPClassic();
+
+ void setHomeDir(QString home);
+
+ bool running;
+
+private:
+ Ui::LPClassic *ui;
+ QTimer *fCheck;
+ QProcess *tarProc;
+ QString tarBaseDir, tarDir, tarFile;
+ bool stopped;
+ QFileInfo *tarInfo;
+
+private slots:
+ void updateFCheck();
+ void slotTarDone();
+
+ //Exclude list controls
+ void on_tool_rmexclude_clicked();
+ void on_tool_addexcludefile_clicked();
+ void on_tool_addexcludedir_clicked();
+ void on_list_exclude_itemSelectionChanged();
+
+ //Main Buttons
+ void on_push_cancel_clicked();
+ void on_push_start_clicked();
+ void on_push_stop_clicked();
+ void on_push_finished_clicked();
+
+};
+
+#endif
View
343 src-qt4/life-preserver/lp-gui/LPClassic.ui
@@ -0,0 +1,343 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LPClassic</class>
+ <widget class="QDialog" name="LPClassic">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>265</width>
+ <height>263</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Classic Home-Dir Backup</string>
+ </property>
+ <property name="windowIcon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/box_add.png</normaloff>:/images/box_add.png</iconset>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QStackedWidget" name="stackedWidget">
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <widget class="QWidget" name="page_setup">
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Filename:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="line_filename"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="check_pbidesktop">
+ <property name="text">
+ <string>Exclude PBI Shortcuts</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="check_userbin">
+ <property name="text">
+ <string>Exclude User-Level Binaries (~/bin/)</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Line" name="line_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Additional Excludes</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QListWidget" name="list_exclude"/>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QToolButton" name="tool_rmexclude">
+ <property name="toolTip">
+ <string>Remove selected exclude</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/list-remove.png</normaloff>:/images/list-remove.png</iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QToolButton" name="tool_addexcludefile">
+ <property name="toolTip">
+ <string>Exclude file(s)</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/copy.png</normaloff>:/images/copy.png</iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="tool_addexcludedir">
+ <property name="toolTip">
+ <string>Exclude a directory</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/folder.png</normaloff>:/images/folder.png</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="push_cancel">
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/application-exit.png</normaloff>:/images/application-exit.png</iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="push_start">
+ <property name="text">
+ <string>Start</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/system-run.png</normaloff>:/images/system-run.png</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="page_running">
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label_status">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>Home Directory Being Archived....</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>60</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_fullfilename">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string notr="true">/home/&lt;filename&gt;.home.tar.gz</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="maximum">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>-1</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Size:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_size">
+ <property name="text">
+ <string notr="true">??</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>60</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QPushButton" name="push_stop">
+ <property name="text">
+ <string>Stop</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/backup-failed.png</normaloff>:/images/backup-failed.png</iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="push_finished">
+ <property name="text">
+ <string>Finished</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/backup-ok.png</normaloff>:/images/backup-ok.png</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources>
+ <include location="lPreserve.qrc"/>
+ </resources>
+ <connections/>
+</ui>
View
3 src-qt4/life-preserver/lp-gui/LPGUtils.cpp
@@ -141,13 +141,16 @@ QString LPGUtils::generateReversionFileName(QString fileName, QString destDir){
}
bool LPGUtils::revertFile(QString oldPath, QString newPath){
+ qDebug() << "Reverting file:" << oldPath << " -> " << newPath;
bool ok = QFile::copy(oldPath,newPath);
//return the path to the new file if the copy was successful
if(ok){
//reset the permissions on the reverted file to match the original
QFile::setPermissions(newPath, QFile::permissions(oldPath));
QFileInfo FI(oldPath);
system( QString("chown "+FI.owner()+":"+FI.group()+" "+newPath).toUtf8() );
+ }else{
+ qDebug() << " - Error: Could not copy file";
}
return ok;
}
View
18 src-qt4/life-preserver/lp-gui/LPMain.cpp
@@ -20,6 +20,8 @@ LPMain::LPMain(QWidget *parent) : QMainWindow(parent), ui(new Ui::LPMain){
watcher->addPath("/var/log/lpreserver/");
//Initialize the waitbox pointer
waitBox = 0;
+ //Initialize the classic dialog pointer
+ classicDLG = 0;
//Create the basic/advanced view options
viewBasic = new QRadioButton(tr("Basic"), ui->menuView);
QWidgetAction *WABasic = new QWidgetAction(this); WABasic->setDefaultWidget(viewBasic);
@@ -521,6 +523,19 @@ void LPMain::menuCloseWindow(){
void LPMain::menuCompressHomeDir(QAction* act){
QString user = act->text();
qDebug() << "Compress Home Dir:" << user;
+ //Start up the Classic Dialog
+ bool recreate = false;
+ if(classicDLG == 0){ recreate = true; }
+ if(recreate){
+ classicDLG = new LPClassic(this);
+ classicDLG->setHomeDir("/usr/home/"+user);
+ classicDLG->show();
+ }else if(!classicDLG->running){
+ classicDLG->setHomeDir("/usr/home/"+user); //move to the alternate user dir
+ }
+ classicDLG->raise();
+ classicDLG->show();
+ /*
//Prompt for the package name
QString pkgName = user+"-"+QDateTime::currentDateTime().toString("yyyyMMdd-hhmm");
bool ok;
@@ -537,7 +552,8 @@ void LPMain::menuCompressHomeDir(QAction* act){
}else{
qDebug() << "Package created at:" << pkgPath;
QMessageBox::information(this,tr("Package Success"), tr("The home directory package was successfully created.")+"\n\n"+pkgPath);
- }
+ }
+ */
}
void LPMain::menuExtractHomeDir(){
View
2 src-qt4/life-preserver/lp-gui/LPMain.h
@@ -22,6 +22,7 @@
#include "LPGUtils.h"
#include "LPWizard.h"
#include "LPConfig.h"
+#include "LPClassic.h"
namespace Ui{
class LPMain;
@@ -46,6 +47,7 @@ public slots:
QFileSystemWatcher *watcher;
QTimer *timer;
QSettings *settings;
+ LPClassic *classicDLG;
void showErrorDialog(QString title, QString message, QString errors);
void showWaitBox(QString message);
View
9 src-qt4/life-preserver/lp-gui/lp-gui.pro
@@ -9,20 +9,23 @@ HEADERS += LPBackend.h \
LPContainers.h \
LPConfig.h \
LPMain.h \
- LPGUtils.h
+ LPGUtils.h \
+ LPClassic.h
SOURCES += main.cpp \
LPBackend.cpp \
LPWizard.cpp \
LPConfig.cpp \
LPMain.cpp \
- LPGUtils.cpp
+ LPGUtils.cpp \
+ LPClassic.cpp
RESOURCES += lPreserve.qrc
FORMS = LPWizard.ui \
LPConfig.ui \
- LPMain.ui
+ LPMain.ui \
+ LPClassic.ui
TARGET=life-preserver
target.path=/usr/local/bin

0 comments on commit 7fa3570

Please sign in to comment.