Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a26890e2 authored by David Barchiesi's avatar David Barchiesi

Add properties plugin for viewing Google Drive related information.

parent 71e26730
add_subdirectory(copyurlitemaction)
add_subdirectory(propertiesplugin)
set(gdrivepropertiesplugin_SRCS
gdrivepropertiesplugin.cpp
../../gdrivedebug.cpp
)
ki18n_wrap_ui(gdrivepropertiesplugin_UI_SRCS gdrivepropertiesplugin.ui)
add_library(gdrivepropertiesplugin MODULE ${gdrivepropertiesplugin_UI_SRCS} ${gdrivepropertiesplugin_SRCS})
target_link_libraries(gdrivepropertiesplugin
KF5::I18n
KF5::KIOWidgets
)
install(TARGETS gdrivepropertiesplugin DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES gdrivepropertiesplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
/*
* Copyright 2020 David Barchiesi <d.barchiesi@reply.it>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#include "gdrivepropertiesplugin.h"
#include "../../gdrivedebug.h"
#include "../../gdrive_udsentry.h"
#include <KPluginFactory>
#include <KPluginLoader>
#include <QClipboard>
#include <QDesktopServices>
K_PLUGIN_FACTORY(GDrivePropertiesPluginFactory, registerPlugin<GDrivePropertiesPlugin>();)
GDrivePropertiesPlugin::GDrivePropertiesPlugin(QObject *parent, const QList<QVariant> &args)
: KPropertiesDialogPlugin(qobject_cast<KPropertiesDialog *>(parent))
{
Q_UNUSED(args);
// Ignore if more than one file is selected
if (properties->items().size() != 1) {
qCDebug(GDRIVE) << "Can't show Google Drive properties tab for more than one item";
return;
}
const KFileItem item = properties->items().at(0);
// Ignore if not a Google Drive url
if (item.url().scheme() != QLatin1String("gdrive")) {
qCDebug(GDRIVE) << "Can't show Google Drive properties for non Google Drive entries";
return;
}
const KIO::UDSEntry entry = item.entry();
ui.setupUi(&widget);
const QString id = entry.stringValue(static_cast<unsigned int>(GDriveUDSEntryExtras::Id));
ui.idValue->setText(id);
const QString created = item.timeString(KFileItem::CreationTime);
ui.createdValue->setText(created);
const QString modified = item.timeString(KFileItem::ModificationTime);
ui.modifiedValue->setText(modified);
const QString lastViewedByMe = item.timeString(KFileItem::AccessTime);
ui.lastViewedByMeValue->setText(lastViewedByMe);
const QString version = entry.stringValue(static_cast<unsigned int>(GDriveUDSEntryExtras::Version));
ui.versionValue->setText(version);
const QString md5 = entry.stringValue(static_cast<unsigned int>(GDriveUDSEntryExtras::Md5));
ui.md5Value->setText(md5);
const QString lastModifyingUserName = entry.stringValue(static_cast<unsigned int>(GDriveUDSEntryExtras::LastModifyingUser));
ui.lastModifiedByValue->setText(lastModifyingUserName);
const QString owners = entry.stringValue(static_cast<unsigned int>(GDriveUDSEntryExtras::Owners));
ui.ownersValue->setText(owners);
const QString description = entry.stringValue(KIO::UDSEntry::UDS_COMMENT);
ui.descriptionValue->setText(description);
const QString gdriveLink = entry.stringValue(static_cast<unsigned int>(GDriveUDSEntryExtras::Url));
connect(ui.urlOpenButton, &QPushButton::clicked, this, [gdriveLink]() {
QDesktopServices::openUrl(QUrl(gdriveLink));
});
connect(ui.urlCopyButton, &QPushButton::clicked, this, [gdriveLink]() {
QGuiApplication::clipboard()->setText(gdriveLink);
});
properties->addPage(&widget, "G&oogle Drive");
}
GDrivePropertiesPlugin::~GDrivePropertiesPlugin() = default;
#include "gdrivepropertiesplugin.moc"
[Desktop Entry]
Type=Service
Icon=folder-gdrive
Name=Google Drive Properties Page
Comment=Properties page showing additional information regarding a Google Drive item
X-KDE-Library=gdrivepropertiesplugin
X-KDE-ServiceTypes=KPropertiesDialog/Plugin
MimeType=inode/directory;application/octet-stream
/*
* Copyright 2020 David Barchiesi <david@barchie.si>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#ifndef GDRIVEPROPERTIESPLUGIN_H
#define GDRIVEPROPERTIESPLUGIN_H
#include <KPropertiesDialog>
#include "ui_gdrivepropertiesplugin.h"
class GDrivePropertiesPlugin : public KPropertiesDialogPlugin
{
Q_OBJECT
public:
explicit GDrivePropertiesPlugin(QObject *parent, const QList<QVariant> &args);
~GDrivePropertiesPlugin() override;
private:
QWidget widget;
Ui::GDrivePropertiesWidget ui;
};
#endif // GDRIVEPROPERTIESPLUGIN_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GDrivePropertiesWidget</class>
<widget class="QWidget" name="GDrivePropertiesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>783</width>
<height>612</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="idLabel">
<property name="text">
<string>Id:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="idValue">
<property name="text">
<string notr="true">idValue</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="descriptionLabel">
<property name="text">
<string>Description:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="descriptionValue">
<property name="text">
<string notr="true">descriptionValue</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="ownersLabel">
<property name="text">
<string>Owners:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="ownersValue">
<property name="text">
<string notr="true">ownersValue</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="createdLabel">
<property name="text">
<string>Created:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="createdValue">
<property name="text">
<string notr="true">createdValue</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="modifiedLabel">
<property name="text">
<string>Modified:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="modifiedValue">
<property name="text">
<string notr="true">modifiedValue</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lastModifiedByLabel">
<property name="text">
<string>Last modified by:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="lastModifiedByValue">
<property name="text">
<string notr="true">lastModifiedByValue</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lastViewedByMeLabel">
<property name="text">
<string>Last viewed by me:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="lastViewedByMeValue">
<property name="text">
<string notr="true">lastViewedByMeValue</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="versionLabel">
<property name="text">
<string>Version:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="versionValue">
<property name="text">
<string notr="true">versionValue</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="md5Label">
<property name="text">
<string>MD5 checksum:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLabel" name="md5Value">
<property name="text">
<string notr="true">md5Value</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="betweenFormAndButtonsSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<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="urlOpenButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Open in browser</string>
</property>
<property name="icon">
<iconset theme="internet-services">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="urlCopyButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Click to copy the checksum to the clipboard.</string>
</property>
<property name="text">
<string>Copy URL to Clipboard</string>
</property>
<property name="icon">
<iconset theme="edit-copy">
<normaloff>../../../kio/src/widgets</normaloff>../../../kio/src/widgets</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>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -237,7 +237,12 @@ KIO::UDSEntry KIOGDrive::fileToUDSEntry(const FilePtr &origFile, const QString &
entry.fastInsert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH);
}
entry.fastInsert(static_cast<unsigned int>(GDriveUDSEntryExtras::Id), file->id());
entry.fastInsert(static_cast<unsigned int>(GDriveUDSEntryExtras::Url), file->alternateLink().toString());
entry.fastInsert(static_cast<unsigned int>(GDriveUDSEntryExtras::Version), QString::number(file->version()));
entry.fastInsert(static_cast<unsigned int>(GDriveUDSEntryExtras::Md5), file->md5Checksum());
entry.fastInsert(static_cast<unsigned int>(GDriveUDSEntryExtras::LastModifyingUser), file->lastModifyingUserName());
entry.fastInsert(static_cast<unsigned int>(GDriveUDSEntryExtras::Owners), file->ownerNames().join(QStringLiteral(", ")));
return entry;
}
......@@ -823,7 +828,11 @@ void KIOGDrive::mkdir(const QUrl &url, int permissions)
void KIOGDrive::stat(const QUrl &url)
{
qCDebug(GDRIVE) << "Going to stat()" << url;
// TODO We should be using StatDetails to limit how we respond to a stat request
const QString statDetails = metaData(QStringLiteral("statDetails"));
KIO::StatDetails details = statDetails.isEmpty() ? KIO::StatDefaultDetails : static_cast<KIO::StatDetails>(statDetails.toInt());
qCDebug(GDRIVE) << "Going to stat()" << url << "for details" << details;
const auto gdriveUrl = GDriveUrl(url);
if (gdriveUrl.isRoot()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment