mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
karchivemanager: import
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
bca0d01d57
commit
7ae87e89f7
9 changed files with 2188 additions and 0 deletions
27
karchivemanager/CMakeLists.txt
Normal file
27
karchivemanager/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
project(karchivemanager)
|
||||
|
||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
find_package(KDE4 4.19.0 REQUIRED)
|
||||
include(KDE4Defaults)
|
||||
include_directories(${KDE4_INCLUDES})
|
||||
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
set(karchivemanager_sources
|
||||
strmode.c
|
||||
karchiveapp.cpp
|
||||
karchivemanager.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(karchivemanager ${karchivemanager_sources})
|
||||
target_link_libraries(karchivemanager
|
||||
${KDE4_KDEUI_LIBS}
|
||||
${KDE4_KFILE_LIBS}
|
||||
z
|
||||
bz2
|
||||
archive
|
||||
)
|
||||
|
||||
install(TARGETS karchivemanager DESTINATION ${KDE4_BIN_INSTALL_DIR})
|
||||
install(PROGRAMS karchivemanager.desktop DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR})
|
186
karchivemanager/karchiveapp.cpp
Normal file
186
karchivemanager/karchiveapp.cpp
Normal file
|
@ -0,0 +1,186 @@
|
|||
/* This file is part of KArchiveManager
|
||||
Copyright (C) 2018 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <KFileDialog>
|
||||
#include <KDebug>
|
||||
#include <KLocale>
|
||||
|
||||
#include "karchivemanager.hpp"
|
||||
#include "karchiveapp.hpp"
|
||||
#include "ui_karchiveapp.h"
|
||||
|
||||
class KArchiveAppPrivate {
|
||||
|
||||
public:
|
||||
Ui_KArchiveAppWindow ui;
|
||||
|
||||
KArchiveModel m_model;
|
||||
KArchiveManager *m_archive;
|
||||
};
|
||||
|
||||
KArchiveApp::KArchiveApp()
|
||||
: d(new KArchiveAppPrivate()) {
|
||||
d->ui.setupUi(this);
|
||||
show();
|
||||
|
||||
d->ui.archiveView->setModel(&d->m_model);
|
||||
|
||||
connect(d->ui.actionOpen, SIGNAL(triggered()), this, SLOT(slotOpenAction()));
|
||||
d->ui.actionOpen->setShortcut(QKeySequence::Open);
|
||||
connect(d->ui.actionQuit, SIGNAL(triggered()), this, SLOT(slotQuitAction()));
|
||||
d->ui.actionQuit->setShortcut(QKeySequence::Quit);
|
||||
|
||||
connect(d->ui.actionAdd, SIGNAL(triggered()), this, SLOT(slotAddAction()));
|
||||
connect(d->ui.actionRemove, SIGNAL(triggered()), this, SLOT(slotRemoveAction()));
|
||||
connect(d->ui.actionExtract, SIGNAL(triggered()), this, SLOT(slotExtractAction()));
|
||||
|
||||
connect(d->ui.archiveView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
|
||||
this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
|
||||
connect(&d->m_model, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
|
||||
connect(&d->m_model, SIGNAL(loadFinished()), this, SLOT(slotLoadFinished()));
|
||||
}
|
||||
|
||||
KArchiveApp::~KArchiveApp() {
|
||||
if (d->m_archive) {
|
||||
delete d->m_archive;
|
||||
}
|
||||
delete d;
|
||||
}
|
||||
|
||||
void KArchiveApp::changePath(const QString path) {
|
||||
if (d->m_archive) {
|
||||
delete d->m_archive;
|
||||
}
|
||||
|
||||
d->m_archive = new KArchiveManager(path);
|
||||
d->m_model.loadArchive(d->m_archive);
|
||||
|
||||
statusBar()->showMessage(path);
|
||||
|
||||
const bool iswritable = d->m_archive->writable();
|
||||
d->ui.actionAdd->setEnabled(iswritable);
|
||||
d->ui.actionRemove->setEnabled(iswritable);
|
||||
d->ui.actionExtract->setEnabled(iswritable);
|
||||
}
|
||||
|
||||
void KArchiveApp::slotOpenAction() {
|
||||
// TODO: MIMEs
|
||||
const QString path = KFileDialog::getOpenFileName(KUrl(), QString(), this, i18n("Archive path"));
|
||||
if (!path.isEmpty()) {
|
||||
changePath(path);
|
||||
}
|
||||
}
|
||||
|
||||
void KArchiveApp::slotQuitAction() {
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void KArchiveApp::slotAddAction() {
|
||||
QFileDialog opendialog(this, windowTitle());
|
||||
opendialog.setFileMode(QFileDialog::ExistingFiles);
|
||||
opendialog.exec();
|
||||
const QStringList selected = opendialog.selectedFiles();
|
||||
if (!opendialog.result() || selected.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
kDebug() << "adding" << selected;
|
||||
const QByteArray stripdir = opendialog.directory().path().toUtf8();
|
||||
QString destdir;
|
||||
foreach (const QModelIndex &item, d->ui.archiveView->selectionModel()->selectedIndexes()) {
|
||||
destdir = d->m_model.dir(item);
|
||||
}
|
||||
d->m_archive->add(selected, stripdir + "/", destdir.toUtf8() + "/");
|
||||
|
||||
kDebug() << "reloading archive";
|
||||
d->m_model.loadArchive(d->m_archive);
|
||||
}
|
||||
|
||||
void KArchiveApp::slotRemoveAction() {
|
||||
QStringList selected;
|
||||
foreach (const QModelIndex &item, d->ui.archiveView->selectionModel()->selectedIndexes()) {
|
||||
selected += d->m_model.paths(item);
|
||||
}
|
||||
|
||||
QMessageBox::StandardButton answer = QMessageBox::question(this, windowTitle(),
|
||||
QApplication::tr("Are you sure you want to delete:\n\n%1?").arg(selected.join("\n")),
|
||||
QMessageBox::No | QMessageBox::Yes);
|
||||
if (answer != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
kDebug() << "removing" << selected;
|
||||
d->m_archive->remove(selected);
|
||||
|
||||
kDebug() << "reloading archive";
|
||||
d->m_model.loadArchive(d->m_archive);
|
||||
}
|
||||
|
||||
void KArchiveApp::slotExtractAction() {
|
||||
QStringList selected;
|
||||
foreach (const QModelIndex &item, d->ui.archiveView->selectionModel()->selectedIndexes()) {
|
||||
selected += d->m_model.paths(item);
|
||||
}
|
||||
|
||||
const QString destination = QFileDialog::getExistingDirectory(this, windowTitle());
|
||||
if (destination.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
kDebug() << "extracting" << selected << "to" << destination;
|
||||
d->m_archive->extract(selected, destination, true);
|
||||
}
|
||||
|
||||
void KArchiveApp::slotSelectionChanged(const QItemSelection ¤t, const QItemSelection &previous) {
|
||||
Q_UNUSED(previous);
|
||||
d->ui.menuAction->setEnabled(true);
|
||||
|
||||
if (current.indexes().isEmpty()) {
|
||||
d->ui.menuAction->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void KArchiveApp::slotLoadStarted() {
|
||||
d->ui.menuAction->setEnabled(false);
|
||||
d->ui.archiveView->setEnabled(false);
|
||||
d->ui.progressBar->setRange(0, 0);
|
||||
d->ui.progressBar->setVisible(true);
|
||||
|
||||
QHeaderView* header = d->ui.archiveView->header();
|
||||
if (header) {
|
||||
header->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void KArchiveApp::slotLoadFinished() {
|
||||
d->ui.archiveView->setEnabled(true);
|
||||
d->ui.progressBar->setRange(0, 1);
|
||||
d->ui.progressBar->setVisible(false);
|
||||
|
||||
QHeaderView* header = d->ui.archiveView->header();
|
||||
if (header && header->count() > 0) {
|
||||
header->setVisible(true);
|
||||
header->setResizeMode(0, QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
d->m_model.sort(1, Qt::AscendingOrder);
|
||||
}
|
52
karchivemanager/karchiveapp.hpp
Normal file
52
karchivemanager/karchiveapp.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* This file is part of KArchiveManager
|
||||
Copyright (C) 2018 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KARCHIVEAPP_H
|
||||
#define KARCHIVEAPP_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QItemSelection>
|
||||
|
||||
class KArchiveAppPrivate;
|
||||
|
||||
class KArchiveApp : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KArchiveApp();
|
||||
~KArchiveApp();
|
||||
|
||||
void changePath(const QString path);
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotOpenAction();
|
||||
void slotQuitAction();
|
||||
void slotAddAction();
|
||||
void slotRemoveAction();
|
||||
void slotExtractAction();
|
||||
|
||||
void slotSelectionChanged(const QItemSelection ¤t, const QItemSelection &previous);
|
||||
|
||||
void slotLoadStarted();
|
||||
void slotLoadFinished();
|
||||
|
||||
private:
|
||||
KArchiveAppPrivate *d;
|
||||
};
|
||||
|
||||
#endif // KARCHIVEAPP_H
|
127
karchivemanager/karchiveapp.ui
Normal file
127
karchivemanager/karchiveapp.ui
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>KArchiveAppWindow</class>
|
||||
<widget class="QMainWindow" name="KArchiveAppWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>499</width>
|
||||
<height>426</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Archive Manager</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset theme="package-x-generic">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="archiveView">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectItems</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>499</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionOpen"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuAction">
|
||||
<property name="title">
|
||||
<string>Action</string>
|
||||
</property>
|
||||
<addaction name="actionAdd"/>
|
||||
<addaction name="actionRemove"/>
|
||||
<addaction name="actionExtract"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuAction"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionOpen">
|
||||
<property name="icon">
|
||||
<iconset theme="document-open">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionQuit">
|
||||
<property name="icon">
|
||||
<iconset theme="process-stop">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAdd">
|
||||
<property name="icon">
|
||||
<iconset theme="list-add">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRemove">
|
||||
<property name="icon">
|
||||
<iconset theme="list-remove">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExtract">
|
||||
<property name="icon">
|
||||
<iconset theme="document-export">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Extract</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
1361
karchivemanager/karchivemanager.cpp
Normal file
1361
karchivemanager/karchivemanager.cpp
Normal file
File diff suppressed because it is too large
Load diff
10
karchivemanager/karchivemanager.desktop
Normal file
10
karchivemanager/karchivemanager.desktop
Normal file
|
@ -0,0 +1,10 @@
|
|||
[Desktop Entry]
|
||||
Icon=package-x-generic
|
||||
Name=KArchiveManager
|
||||
GenericName=Archive Manager
|
||||
Comment=Simple archive manager for KDE
|
||||
Exec=karchivemanager --icon '%i' --caption '%c' %U
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=Qt;KDE;System;
|
||||
MimeType=application/x-archive;application/x-deb;application/x-cd-image;application/x-bcpio;application/x-cpio;application/x-cpio-compressed;application/x-sv4cpio;application/x-sv4crc;application/x-rpm;application/x-source-rpm;application/vnd.ms-cab-compressed;application/x-servicepack;application/x-lzop;application/x-lz4;application/x-tar;application/x-compressed-tar;application/x-bzip;application/x-gzip;application/x-bzip-compressed-tar;application/x-gzip-compressed-tar;application/x-tarz;application/x-xz;application/x-xz-compressed-tar;application/x-lzma-compressed-tar;application/x-java-archive;application/zip;application/x-7z-compressed;application/x-iso9660-image;application/x-raw-disk-image;
|
226
karchivemanager/karchivemanager.hpp
Normal file
226
karchivemanager/karchivemanager.hpp
Normal file
|
@ -0,0 +1,226 @@
|
|||
/* This file is part of KArchiveManager
|
||||
Copyright (C) 2018 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KARCHIVEMANAGER_H
|
||||
#define KARCHIVEMANAGER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QStandardItemModel>
|
||||
#include <QDBusArgument>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/*!
|
||||
Archive entry information holder, valid object is obtained via @p KArchiveManager::info
|
||||
|
||||
@note It is up to the programmer to keep the integrity of the structure
|
||||
@note D-Bus signature for the type is <b>(bxxxussssi)</b>
|
||||
@warning The structure is not very portable (size, gid, uid)
|
||||
@ingroup Types
|
||||
|
||||
@see KArchiveManager
|
||||
@see https://dbus.freedesktop.org/doc/dbus-specification.html#container-types
|
||||
*/
|
||||
class KArchiveInfo {
|
||||
|
||||
public:
|
||||
enum KArchiveType {
|
||||
None = 0,
|
||||
File = 1,
|
||||
Directory = 2,
|
||||
Link = 3,
|
||||
Character = 4,
|
||||
Block = 5,
|
||||
Fifo = 6,
|
||||
Socket = 7,
|
||||
};
|
||||
|
||||
KArchiveInfo();
|
||||
KArchiveInfo(const KArchiveInfo &info);
|
||||
|
||||
bool encrypted;
|
||||
int64_t size;
|
||||
int64_t gid;
|
||||
int64_t uid;
|
||||
mode_t mode;
|
||||
time_t atime;
|
||||
time_t ctime;
|
||||
time_t mtime;
|
||||
QByteArray hardlink;
|
||||
QByteArray symlink;
|
||||
QByteArray pathname;
|
||||
QByteArray mimetype;
|
||||
KArchiveType type;
|
||||
|
||||
//! @brief Fancy encrypted for the purpose of widgets
|
||||
QString fancyEncrypted() const;
|
||||
//! @brief Fancy size for the purpose of widgets
|
||||
QString fancySize() const;
|
||||
//! @brief Fancy mode for the purpose of widgets
|
||||
QString fancyMode() const;
|
||||
|
||||
//! @brief Fancy type for the purpose of widgets
|
||||
QString fancyType() const;
|
||||
//! @brief Fancy icon for the purpose of widgets
|
||||
QIcon fancyIcon() const;
|
||||
|
||||
//! @brief Returns if the info is valid or not
|
||||
bool isNull() const;
|
||||
|
||||
bool operator==(const KArchiveInfo &i) const;
|
||||
KArchiveInfo &operator=(const KArchiveInfo &i);
|
||||
};
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug, const KArchiveInfo &i);
|
||||
#endif
|
||||
const QDBusArgument &operator<<(QDBusArgument &, const KArchiveInfo &i);
|
||||
const QDBusArgument &operator>>(const QDBusArgument &, KArchiveInfo &i);
|
||||
|
||||
class KArchiveManagerPrivate;
|
||||
|
||||
/*!
|
||||
Archive manager with support for many formats, provides plain GZip and BZip2 support aswell
|
||||
|
||||
Example:
|
||||
\code
|
||||
KArchiveManager archive("/home/joe/archive.tar.gz");
|
||||
kDebug() << archive.list();
|
||||
|
||||
QDir::mkpath("/tmp/destination");
|
||||
archive.extract("dir/in/archive/", "/tmp/destination");
|
||||
archive.delete("file/in/archive.txt");
|
||||
\endcode
|
||||
|
||||
@note Paths ending with "/" will be considered as directories
|
||||
@warning The operations are done on temporary file, copy of the orignal, which after
|
||||
successfull operation (add or remove) replaces the orignal thus if it is interrupted the
|
||||
source may get corrupted
|
||||
|
||||
@see KArchiveInfo
|
||||
|
||||
@todo encrypted paths handling
|
||||
@todo make listing consistent by faking dir info?
|
||||
@todo error reporting
|
||||
*/
|
||||
class KArchiveManager {
|
||||
|
||||
public:
|
||||
KArchiveManager(const QString &path);
|
||||
~KArchiveManager();
|
||||
|
||||
/*!
|
||||
@brief Add paths to the archive
|
||||
@param strip string to remove from the start of every path
|
||||
@param destination relative path where paths should be added to
|
||||
*/
|
||||
bool add(const QStringList &paths, const QByteArray &strip = "/", const QByteArray &destination = "") const;
|
||||
//! @brief Remove paths from the archive
|
||||
bool remove(const QStringList &paths) const;
|
||||
/*!
|
||||
@brief Extract paths to destination
|
||||
@param destination existing directory, you can use @p QDir::mkpath(QString)
|
||||
@param preserve preserve advanced attributes (ACL/ATTR)
|
||||
*/
|
||||
bool extract(const QStringList &paths, const QString &destination, bool preserve = true) const;
|
||||
|
||||
/*!
|
||||
@brief List the content of the archive
|
||||
@note may return empty list on both failure and success
|
||||
@note some formats list directories, some do not
|
||||
@todo report failure somehow
|
||||
*/
|
||||
QList<KArchiveInfo> list() const;
|
||||
|
||||
//! @brief Get info for archive entry
|
||||
KArchiveInfo info(const QString &path) const;
|
||||
|
||||
//! @brief Report if path is writable archive
|
||||
bool writable() const;
|
||||
//! @brief Report if path is supported archive
|
||||
static bool supported(const QString &path);
|
||||
|
||||
//! @brief Read gzip compressed path into buffer
|
||||
static bool gzipRead(const QString &path, QByteArray &buffer);
|
||||
//! @brief Compress data as gzip and write it to path
|
||||
static bool gzipWrite(const QString &path, const QByteArray &data);
|
||||
//! @brief Read bzip2 compressed path into buffer
|
||||
static bool bzipRead(const QString &path, QByteArray &buffer);
|
||||
//! @brief Compress data as bzip2 and write it to path
|
||||
static bool bzipWrite(const QString &path, QByteArray data);
|
||||
|
||||
private:
|
||||
KArchiveManagerPrivate *d;
|
||||
};
|
||||
|
||||
class KArchiveModelPrivate;
|
||||
|
||||
/*!
|
||||
Custom item model for displaying archives in tree views (@p QTreeView)
|
||||
|
||||
Example:
|
||||
\code
|
||||
QTreeView view;
|
||||
KArchiveModel model;
|
||||
KArchiveManager archive("/home/joe/archive.tar.gz");
|
||||
|
||||
view.setModel(model);
|
||||
model.loadArchive(&archive);
|
||||
\endcode
|
||||
|
||||
@see KArchiveManager, KArchiveInfo
|
||||
*/
|
||||
class KArchiveModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KArchiveModel(QObject *parent = Q_NULLPTR);
|
||||
~KArchiveModel();
|
||||
|
||||
//! @brief Load archive into the model
|
||||
bool loadArchive(const KArchiveManager *archive);
|
||||
//! @brief Get path for index, propagates to parents to retrieve the full path
|
||||
QString path(const QModelIndex &index) const;
|
||||
/*!
|
||||
@brief Get paths for index, propagates to childs to retrieve all sub-paths.
|
||||
Usefull for obtaining the selected item paths for add, remove and extract
|
||||
operations
|
||||
*/
|
||||
QStringList paths(const QModelIndex &index) const;
|
||||
/*!
|
||||
@brief Get parent directory for index. Usefull for obtaining the current dir
|
||||
for add operations
|
||||
*/
|
||||
QString dir(const QModelIndex &index) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
//! @brief Signals load was started
|
||||
void loadStarted();
|
||||
//! @brief Signals load was finished
|
||||
void loadFinished();
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotLoadFinished();
|
||||
|
||||
private:
|
||||
KArchiveModelPrivate *d;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(KArchiveInfo);
|
||||
|
||||
#endif // KARCHIVEMANAGER_H
|
56
karchivemanager/main.cpp
Normal file
56
karchivemanager/main.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* This file is part of KArchiveManager
|
||||
Copyright (C) 2018 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <KAboutData>
|
||||
#include <KCmdLineArgs>
|
||||
#include <KUniqueApplication>
|
||||
#include <KUrl>
|
||||
|
||||
#include "karchiveapp.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
KAboutData aboutData("karchivemanager", 0, ki18n("Archive Manager"),
|
||||
"1.0.0", ki18n("Simple archive manager for KDE."),
|
||||
KAboutData::License_GPL_V2,
|
||||
ki18n("(c) 2018 Ivailo Monev"),
|
||||
KLocalizedString(),
|
||||
"http://github.com/fluxer/katana"
|
||||
);
|
||||
|
||||
aboutData.addAuthor(ki18n("Ivailo Monev"),
|
||||
ki18n("Maintainer"),
|
||||
"xakepa10@gmail.com");
|
||||
aboutData.setProgramIconName(QLatin1String("package-x-generic"));
|
||||
|
||||
KCmdLineArgs::init(argc, argv, &aboutData);
|
||||
KCmdLineOptions option;
|
||||
option.add("+[url]", ki18n("URL to be opened"));
|
||||
KCmdLineArgs::addCmdLineOptions(option);
|
||||
|
||||
KApplication *karchiveapp = new KApplication();
|
||||
KArchiveApp *karchivewin = new KArchiveApp();
|
||||
karchivewin->show();
|
||||
|
||||
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
|
||||
for (int pos = 0; pos < args->count(); ++pos) {
|
||||
karchivewin->changePath(args->url(pos).toLocalFile());
|
||||
}
|
||||
|
||||
return karchiveapp->exec();
|
||||
}
|
143
karchivemanager/strmode.c
Normal file
143
karchivemanager/strmode.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// #include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
strmode(mode_t mode, char *p)
|
||||
{
|
||||
/* print type */
|
||||
switch (mode & S_IFMT) {
|
||||
case S_IFDIR: /* directory */
|
||||
*p++ = 'd';
|
||||
break;
|
||||
case S_IFCHR: /* character special */
|
||||
*p++ = 'c';
|
||||
break;
|
||||
case S_IFBLK: /* block special */
|
||||
*p++ = 'b';
|
||||
break;
|
||||
case S_IFREG: /* regular */
|
||||
*p++ = '-';
|
||||
break;
|
||||
case S_IFLNK: /* symbolic link */
|
||||
*p++ = 'l';
|
||||
break;
|
||||
case S_IFSOCK: /* socket */
|
||||
*p++ = 's';
|
||||
break;
|
||||
#ifdef S_IFIFO
|
||||
case S_IFIFO: /* fifo */
|
||||
*p++ = 'p';
|
||||
break;
|
||||
#endif
|
||||
#ifdef S_IFWHT
|
||||
case S_IFWHT: /* whiteout */
|
||||
*p++ = 'w';
|
||||
break;
|
||||
#endif
|
||||
default: /* unknown */
|
||||
*p++ = '?';
|
||||
break;
|
||||
}
|
||||
/* usr */
|
||||
if (mode & S_IRUSR)
|
||||
*p++ = 'r';
|
||||
else
|
||||
*p++ = '-';
|
||||
if (mode & S_IWUSR)
|
||||
*p++ = 'w';
|
||||
else
|
||||
*p++ = '-';
|
||||
switch (mode & (S_IXUSR | S_ISUID)) {
|
||||
case 0:
|
||||
*p++ = '-';
|
||||
break;
|
||||
case S_IXUSR:
|
||||
*p++ = 'x';
|
||||
break;
|
||||
case S_ISUID:
|
||||
*p++ = 'S';
|
||||
break;
|
||||
case S_IXUSR | S_ISUID:
|
||||
*p++ = 's';
|
||||
break;
|
||||
}
|
||||
/* group */
|
||||
if (mode & S_IRGRP)
|
||||
*p++ = 'r';
|
||||
else
|
||||
*p++ = '-';
|
||||
if (mode & S_IWGRP)
|
||||
*p++ = 'w';
|
||||
else
|
||||
*p++ = '-';
|
||||
switch (mode & (S_IXGRP | S_ISGID)) {
|
||||
case 0:
|
||||
*p++ = '-';
|
||||
break;
|
||||
case S_IXGRP:
|
||||
*p++ = 'x';
|
||||
break;
|
||||
case S_ISGID:
|
||||
*p++ = 'S';
|
||||
break;
|
||||
case S_IXGRP | S_ISGID:
|
||||
*p++ = 's';
|
||||
break;
|
||||
}
|
||||
/* other */
|
||||
if (mode & S_IROTH)
|
||||
*p++ = 'r';
|
||||
else
|
||||
*p++ = '-';
|
||||
if (mode & S_IWOTH)
|
||||
*p++ = 'w';
|
||||
else
|
||||
*p++ = '-';
|
||||
switch (mode & (S_IXOTH | S_ISVTX)) {
|
||||
case 0:
|
||||
*p++ = '-';
|
||||
break;
|
||||
case S_IXOTH:
|
||||
*p++ = 'x';
|
||||
break;
|
||||
case S_ISVTX:
|
||||
*p++ = 'T';
|
||||
break;
|
||||
case S_IXOTH | S_ISVTX:
|
||||
*p++ = 't';
|
||||
break;
|
||||
}
|
||||
*p++ = ' '; /* will be a '+' if ACL's implemented */
|
||||
*p = '\0';
|
||||
}
|
Loading…
Add table
Reference in a new issue