WIP: more functionality for Salt Package Manager

This commit is contained in:
Matthias Koefferlein 2017-03-18 22:36:33 +01:00
parent b8238a85f9
commit 3a6e4982c8
14 changed files with 626 additions and 62 deletions

View File

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Manage Packages</string>
<string>Salt Package Manager</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
@ -55,7 +55,7 @@
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_4">
<widget class="QToolButton" name="install_button">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
@ -88,7 +88,7 @@
</spacer>
</item>
<item>
<widget class="QToolButton" name="toolButton_2">
<widget class="QToolButton" name="create_button">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
@ -108,7 +108,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_3">
<widget class="QToolButton" name="delete_button">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
@ -131,7 +131,7 @@
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QStackedWidget" name="list_stack">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -160,6 +160,12 @@
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="selectionRectVisible">
<bool>true</bool>
</property>
@ -215,42 +221,101 @@
<rect>
<x>0</x>
<y>0</y>
<width>218</width>
<height>138</height>
<width>320</width>
<height>204</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="1">
<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>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="layResources.qrc">:/salt.png</pixmap>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>&lt;h1&gt;Salt Package Manager&lt;/h1&gt;</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>&lt;html&gt;&lt;body&gt;&lt;center&gt;No packages are installed currently.&lt;br&gt;&lt;br&gt;You can use:&lt;br&gt;
&lt;/center&gt;
<string>&lt;html&gt;&lt;body&gt;&lt;h4&gt;No packages are installed currently.&lt;/h4&gt;&lt;p&gt;Use&lt;br/&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td width=&quot;30&quot;&gt;&lt;a href=&quot;:import&quot;&gt;&lt;img src=&quot;:/import.png&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;to import a package from an external source&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;30&quot;&gt;&lt;a href=&quot;:import&quot;&gt;&lt;img src=&quot;:/import.png&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;to import a package from an&lt;br/&gt;external repository&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;:add&quot;&gt;&lt;img src=&quot;:/add.png&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;to create a new package&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<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>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
@ -264,7 +329,7 @@
</item>
</layout>
</widget>
<widget class="QFrame" name="frame">
<widget class="QFrame" name="details_frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
@ -299,7 +364,7 @@
</font>
</property>
<property name="text">
<string>Package Details</string>
<string>Details</string>
</property>
</widget>
</item>
@ -321,7 +386,11 @@
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QTextBrowser" name="textBrowser"/>
<widget class="lay::SaltGrainDetailsTextWidget" name="details_text">
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
@ -335,15 +404,6 @@
</widget>
</item>
</layout>
<action name="actionNewFolder">
<property name="icon">
<iconset resource="layResources.qrc">
<normaloff>:/new_folder.png</normaloff>:/new_folder.png</iconset>
</property>
<property name="text">
<string>New Folder</string>
</property>
</action>
<action name="actionNew">
<property name="icon">
<iconset resource="layResources.qrc">
@ -353,7 +413,7 @@
<string>New</string>
</property>
<property name="toolTip">
<string>New Package</string>
<string>New package</string>
</property>
</action>
<action name="actionDelete">
@ -365,19 +425,7 @@
<string>Delete</string>
</property>
<property name="toolTip">
<string>Delete Package</string>
</property>
</action>
<action name="actionRename">
<property name="icon">
<iconset resource="layResources.qrc">
<normaloff>:/rename.png</normaloff>:/rename.png</iconset>
</property>
<property name="text">
<string>Rename</string>
</property>
<property name="toolTip">
<string>Rename Package</string>
<string>Delete package</string>
</property>
</action>
<action name="actionImport">
@ -389,16 +437,23 @@
<string>Import</string>
</property>
<property name="toolTip">
<string>Import Package</string>
<string>Import package</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>lay::SaltGrainDetailsTextWidget</class>
<extends>QTextBrowser</extends>
<header>laySaltGrainDetailsTextWidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>salt_view</tabstop>
<tabstop>toolButton_4</tabstop>
<tabstop>toolButton_2</tabstop>
<tabstop>toolButton_3</tabstop>
<tabstop>textBrowser</tabstop>
<tabstop>install_button</tabstop>
<tabstop>create_button</tabstop>
<tabstop>delete_button</tabstop>
<tabstop>details_text</tabstop>
</tabstops>
<resources>
<include location="layResources.qrc"/>

BIN
src/lay/images/salt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -49,7 +49,8 @@ HEADERS = \
laySalt.h \
laySaltGrain.h \
laySaltGrains.h \
laySaltManagerDialog.h
laySaltManagerDialog.h \
laySaltGrainDetailsTextWidget.h
FORMS = \
ClipDialog.ui \
@ -142,7 +143,8 @@ SOURCES = \
laySalt.cc \
laySaltGrain.cc \
laySaltGrains.cc \
laySaltManagerDialog.cc
laySaltManagerDialog.cc \
laySaltGrainDetailsTextWidget.cc
RESOURCES = layBuildInMacros.qrc \
layHelpResources.qrc \

View File

@ -113,8 +113,10 @@
<file alias="upup.png">images/upup.png</file>
<file alias="waived.png">images/waived.png</file>
<file alias="yellow_flag.png">images/yellow_flag.png</file>
<file alias="salt.png">images/salt.png</file>
<file alias="salt_icon.png">images/salt_icon.png</file>
</qresource>
<qresource prefix="/syntax" >
<qresource prefix="/syntax">
<file alias="ruby.xml">syntax/ruby.xml</file>
<file alias="python.xml">syntax/python.xml</file>
</qresource>

View File

@ -96,6 +96,14 @@ public:
return m_root.end_collections ();
}
/**
* @brief Returns a value indicating whether the collection is empty
*/
bool is_empty () const
{
return m_root.is_empty ();
}
/**
* @brief A flat iterator of (sorted) grains (begin)
*/

View File

@ -41,12 +41,17 @@ bool
SaltGrain::operator== (const SaltGrain &other) const
{
return m_name == other.m_name &&
m_version == other.m_version &&
m_path == other.m_path &&
m_version == other.m_version &&
m_url == other.m_url &&
m_title == other.m_title &&
m_doc == other.m_doc &&
m_dependencies == other.m_dependencies;
m_dependencies == other.m_dependencies &&
m_author == other.m_author &&
m_author_contact == other.m_author_contact &&
m_license == other.m_license &&
m_authored_time == other.m_authored_time &&
m_installed_time == other.m_installed_time;
}
void
@ -85,6 +90,36 @@ SaltGrain::set_doc (const std::string &t)
m_doc = t;
}
void
SaltGrain::set_author (const std::string &a)
{
m_author = a;
}
void
SaltGrain::set_author_contact (const std::string &a)
{
m_author_contact = a;
}
void
SaltGrain::set_license (const std::string &l)
{
m_license = l;
}
void
SaltGrain::set_authored_time (const QDateTime &t)
{
m_authored_time = t;
}
void
SaltGrain::set_installed_time (const QDateTime &t)
{
m_installed_time = t;
}
int
SaltGrain::compare_versions (const std::string &v1, const std::string &v2)
{
@ -128,12 +163,38 @@ SaltGrain::compare_versions (const std::string &v1, const std::string &v2)
}
}
struct TimeConverter
{
std::string to_string (const QDateTime &time) const
{
if (time.isNull ()) {
return std::string ();
} else {
return tl::to_string (time.toString (Qt::ISODate));
}
}
void from_string (const std::string &time, QDateTime &res) const
{
if (time.empty ()) {
res = QDateTime ();
} else {
res = QDateTime::fromString (tl::to_qstring (time), Qt::ISODate);
}
}
};
static tl::XMLStruct<lay::SaltGrain> xml_struct ("salt-grain",
tl::make_member (&SaltGrain::name, &SaltGrain::set_name, "name") +
tl::make_member (&SaltGrain::version, &SaltGrain::set_version, "version") +
tl::make_member (&SaltGrain::title, &SaltGrain::set_title, "title") +
tl::make_member (&SaltGrain::doc, &SaltGrain::set_doc, "doc") +
tl::make_member (&SaltGrain::url, &SaltGrain::set_url, "url") +
tl::make_member (&SaltGrain::license, &SaltGrain::set_license, "license") +
tl::make_member (&SaltGrain::author, &SaltGrain::set_author, "author") +
tl::make_member (&SaltGrain::author_contact, &SaltGrain::set_author_contact, "author-contact") +
tl::make_member (&SaltGrain::authored_time, &SaltGrain::set_authored_time, "authored-time", TimeConverter ()) +
tl::make_member (&SaltGrain::installed_time, &SaltGrain::set_installed_time, "installed-time", TimeConverter ()) +
tl::make_element (&SaltGrain::begin_dependencies, &SaltGrain::end_dependencies, &SaltGrain::add_dependency, "depends",
tl::make_member (&SaltGrain::Dependency::name, "name") +
tl::make_member (&SaltGrain::Dependency::url, "url") +

View File

@ -26,6 +26,8 @@
#include "layCommon.h"
#include "tlObject.h"
#include <QTime>
namespace lay
{
@ -142,6 +144,71 @@ public:
*/
void set_version (const std::string &v);
/**
* @brief Gets the author of the grain
*/
const std::string &author () const
{
return m_author;
}
/**
* @brief Sets the author of the grain
*/
void set_author (const std::string &a);
/**
* @brief Gets the author's contact
*/
const std::string &author_contact () const
{
return m_author_contact;
}
/**
* @brief Sets the author's contact
*/
void set_author_contact (const std::string &a);
/**
* @brief Gets the license of the grain
*/
const std::string &license () const
{
return m_license;
}
/**
* @brief Sets the license of the grain
*/
void set_license (const std::string &l);
/**
* @brief Gets the release date and/or time of the grain
*/
const QDateTime &authored_time () const
{
return m_authored_time;
}
/**
* @brief Sets the release date and/or time
*/
void set_authored_time (const QDateTime &t);
/**
* @brief Gets the installation date and/or time of the grain
*/
const QDateTime &installed_time () const
{
return m_installed_time;
}
/**
* @brief Sets the installation date and/or time
*/
void set_installed_time (const QDateTime &t);
/**
* @brief Gets the absolute file path of the installed grain
* This is the file path to the grain folder.
@ -261,6 +328,10 @@ private:
std::string m_url;
std::string m_title;
std::string m_doc;
std::string m_author;
std::string m_author_contact;
std::string m_license;
QDateTime m_authored_time, m_installed_time;
std::vector<Dependency> m_dependencies;
};

View File

@ -0,0 +1,148 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "laySaltGrainDetailsTextWidget.h"
#include "laySaltGrain.h"
#include "tlString.h"
#include <QTextStream>
#include <QBuffer>
#include <QIcon>
namespace lay
{
SaltGrainDetailsTextWidget::SaltGrainDetailsTextWidget (QWidget *w)
: QTextBrowser (w), mp_grain (0)
{
// .. nothing yet ..
}
void SaltGrainDetailsTextWidget::set_grain (SaltGrain *g)
{
if (mp_grain != g) {
mp_grain = g;
setHtml (details_text ());
}
}
QVariant
SaltGrainDetailsTextWidget::loadResource (int type, const QUrl &url)
{
if (url.path () == QString::fromUtf8 ("/icon")) {
// @@@
return QImage (":/salt_icon.png");
// @@@
} else {
return QTextBrowser::loadResource (type, url);
}
}
QString
SaltGrainDetailsTextWidget::details_text ()
{
SaltGrain *g = mp_grain;
if (! g) {
return QString ();
}
QBuffer buffer;
buffer.open (QIODevice::WriteOnly);
QTextStream stream (&buffer);
stream.setCodec ("UTF-8");
stream << "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head><body>";
stream << "<table><tr>";
stream << "<td><img src=\":/icon\"/></td>";
stream << "<td>";
stream << "<h1>";
stream << tl::to_qstring (tl::escaped_to_html (g->name ())) << " " << tl::to_qstring (tl::escaped_to_html (g->version ()));
stream << "</h1>";
if (! g->title ().empty()) {
stream << "<h3>" << tl::to_qstring (tl::escaped_to_html (g->title ())) << "</h3>";
}
if (g->version ().empty ()) {
stream << "<p><i><font color='gray'>";
stream << QObject::tr ("This package does not have a version. "
"Use the &lt;version&gt; element of the specification file or edit the package properties to provide a version.");
stream << "</font></i></p>";
}
if (g->title ().empty ()) {
stream << "<p><i><font color='gray'>";
stream << QObject::tr ("This package does not have a title. "
"Use the &lt;title&gt; element of the specification file or edit the package properties to provide a title.");
stream << "</font></i></p>";
}
stream << "</td></tr></table>";
stream << "<p><br/>";
if (! g->doc ().empty ()) {
stream << tl::to_qstring (tl::escaped_to_html (g->doc ()));
} else {
stream << "<i><font color='gray'>";
stream << QObject::tr ("This package does not have a description. "
"Use the &lt;doc&gt; element of the specification file or edit the package properties to provide a description.");
stream << "</font></i>";
}
stream << "</p>";
stream << "<p>";
if (! g->author ().empty ()) {
stream << "<b>" << QObject::tr ("Author") << ":</b> " << tl::to_qstring (tl::escaped_to_html (g->author ())) << " ";
if (! g->author_contact ().empty ()) {
stream << "(" << tl::to_qstring (tl::escaped_to_html (g->author_contact ())) << ")";
}
if (!g->authored_time ().isNull ()) {
stream << "<br/>";
stream << "<b>" << QObject::tr ("Released") << ":</b> " << g->authored_time ().date ().toString (Qt::ISODate);
}
} else {
stream << "<i><font color='gray'>";
stream << QObject::tr ("This package does not have a author information. "
"Use the &lt;author&gt;, &lt;authored-time&gt; and &lt;author-contact&gt; elements of the specification file or edit the package properties to provide authoring information.");
stream << "</font></i>";
}
stream << "</p>";
stream << "<p>";
if (! g->url ().empty ()) {
stream << "<b>" << QObject::tr ("Documentation link") << ":</b> <a href=\"" << tl::to_qstring (g->url ()) << "\">" << tl::to_qstring (tl::escaped_to_html (g->url ())) << "</a>";
} else {
stream << "<i><font color='gray'>";
stream << QObject::tr ("This package does not have a documentation link. "
"Use the &lt;url&gt; element of the specification file or edit the package properties to provide a link.");
stream << "</font></i>";
}
stream << "</p>";
stream << "</body></html>";
stream.flush ();
return QString::fromUtf8 (buffer.buffer());
}
}

View File

@ -0,0 +1,61 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_laySaltGrainDetailsTextWidget
#define HDR_laySaltGrainDetailsTextWidget
#include <QTextBrowser>
namespace lay
{
class SaltGrain;
/**
* @brief A specialisation of QTextBrowser that displays the details of the salt grain
*/
class SaltGrainDetailsTextWidget
: public QTextBrowser
{
public:
/**
* @brief Constructor
*/
SaltGrainDetailsTextWidget (QWidget *w);
/**
* @brief Sets the grain whose details are to be shown
*/
void set_grain (SaltGrain *g);
protected:
virtual QVariant loadResource (int type, const QUrl &url);
private:
lay::SaltGrain *mp_grain;
QString details_text ();
};
}
#endif

View File

@ -112,7 +112,15 @@ SaltGrains::remove_grain (grain_iterator iter, bool with_files)
bool
SaltGrains::is_empty () const
{
return m_collections.empty () && m_grains.empty ();
if (! m_grains.empty ()) {
return false;
}
for (collections_type::const_iterator i = m_collections.begin (); i != m_collections.end (); ++i) {
if (!i->is_empty ()) {
return false;
}
}
return true;
}
bool

View File

@ -30,10 +30,17 @@
#include <QTextDocument>
#include <QPainter>
#include <QDir>
#include <QTextStream>
#include <QBuffer>
namespace lay
{
// --------------------------------------------------------------------------------------
/**
* @brief A model representing the salt grains for a QListView
*/
class SaltModel
: public QAbstractItemModel
{
@ -71,6 +78,12 @@ public:
return tl::to_qstring (text);
} else if (role == Qt::DecorationRole) {
// @@@
return QIcon (":/salt_icon.png");
// @@@
} else {
return QVariant ();
}
@ -81,7 +94,7 @@ public:
if (parent.isValid ()) {
return QModelIndex ();
} else {
return createIndex (row, column);
return createIndex (row, column, mp_salt->begin_flat () [row]);
}
}
@ -104,10 +117,29 @@ public:
}
}
SaltGrain *grain_from_index (const QModelIndex &index) const
{
if (index.isValid ()) {
return static_cast<SaltGrain *> (index.internalPointer ());
} else {
return 0;
}
}
void update ()
{
// @@@
}
public:
lay::Salt *mp_salt;
};
// --------------------------------------------------------------------------------------
/**
* @brief A delegate displaying the summary of a grain
*/
class SaltItemDelegate
: public QStyledItemDelegate
{
@ -152,13 +184,22 @@ public:
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption (&optionV4, index);
const QListView *view = dynamic_cast<const QListView *> (optionV4.widget);
QSize icon_size (0, 0);
if (view) {
icon_size = view->iconSize ();
}
QTextDocument doc;
doc.setHtml (optionV4.text);
doc.setTextWidth (textWidth);
return QSize (textWidth, doc.size ().height ());
return QSize (textWidth + icon_size.width () + 6, std::max (icon_size.height () + 12, int (doc.size ().height ())));
}
};
// --------------------------------------------------------------------------------------
// SaltManager implementation
// @@@
lay::Salt salt;
static bool salt_initialized = false;
@ -172,16 +213,76 @@ void make_salt ()
// @@@
SaltManagerDialog::SaltManagerDialog (QWidget *parent)
: QDialog (parent)
: QDialog (parent),
m_current_changed_enabled (true)
{
Ui::SaltManagerDialog::setupUi (this);
salt = lay::Salt (); salt_initialized = false; // @@@
make_salt (); // @@@
salt_view->setModel (new SaltModel (this, &salt));
// @@@
salt = lay::Salt (); salt_initialized = false;
make_salt ();
mp_salt = &salt;
// @@@
SaltModel *model = new SaltModel (this, mp_salt);
salt_view->setModel (model);
salt_view->setItemDelegate (new SaltItemDelegate (this));
connect (mp_salt, SIGNAL (collections_changed ()), this, SLOT (salt_changed ()));
// select the first grain
if (model->rowCount (QModelIndex ()) > 0) {
salt_view->setCurrentIndex (model->index (0, 0, QModelIndex ()));
}
salt_changed ();
connect (salt_view->selectionModel (), SIGNAL (currentChanged (const QModelIndex &, const QModelIndex &)), this, SLOT (current_changed ()));
// ...
}
void
SaltManagerDialog::salt_changed ()
{
SaltModel *model = dynamic_cast <SaltModel *> (salt_view->model ());
if (! model) {
return;
}
m_current_changed_enabled = false;
model->update ();
m_current_changed_enabled = true;
if (mp_salt->is_empty ()) {
list_stack->setCurrentIndex (1);
details_frame->hide ();
} else {
list_stack->setCurrentIndex (0);
details_frame->show ();
}
current_changed ();
}
void
SaltManagerDialog::current_changed ()
{
SaltModel *model = dynamic_cast <SaltModel *> (salt_view->model ());
if (! model) {
return;
}
SaltGrain *g = model->grain_from_index (salt_view->currentIndex ());
details_text->set_grain (g);
if (!g) {
details_frame->setEnabled (false);
delete_button->setEnabled (false);
} else {
details_frame->setEnabled (true);
delete_button->setEnabled (true);
}
}
}

View File

@ -30,18 +30,37 @@
namespace lay
{
class Salt;
class SaltGrain;
/**
* @brief The dialog for managing the Salt ("Packages")
*/
class SaltManagerDialog
: public QDialog, private Ui::SaltManagerDialog
{
Q_OBJECT
public:
/**
* @brief Constructor
*/
SaltManagerDialog (QWidget *parent);
private slots:
/**
* @brief Called when the list of packages (grains) has changed
*/
void salt_changed ();
/**
* @brief Called when the currently selected package (grain) has changed
*/
void current_changed ();
private:
lay::Salt *mp_salt;
bool m_current_changed_enabled;
};
}

View File

@ -72,7 +72,20 @@ static std::string salt_to_string (lay::Salt &salt)
TEST (1)
{
std::string tmp0 = tmp_file ("tmp0");
lay::SaltGrain g;
g.save (tmp0);
EXPECT_EQ (g.authored_time ().isNull (), true);
EXPECT_EQ (g.installed_time ().isNull (), true);
lay::SaltGrain g0;
g0.load (tmp0);
EXPECT_EQ (g0.authored_time ().isNull (), true);
EXPECT_EQ (g0.installed_time ().isNull (), true);
EXPECT_EQ (g == g0, true);
std::string tmp = tmp_file ();
g.set_name ("abc");
EXPECT_EQ (g.name (), "abc");
@ -86,6 +99,20 @@ TEST (1)
EXPECT_EQ (g.title (), "title");
g.set_doc ("doc");
EXPECT_EQ (g.doc (), "doc");
g.set_author ("me");
EXPECT_EQ (g.author (), "me");
g.set_author_contact ("ac");
EXPECT_EQ (g.author_contact (), "ac");
g.set_license ("free");
EXPECT_EQ (g.license (), "free");
g.set_authored_time (QDateTime ());
EXPECT_EQ (g.authored_time ().isNull (), true);
g.set_authored_time (QDateTime::fromMSecsSinceEpoch (1000000000));
EXPECT_EQ (QDateTime::fromMSecsSinceEpoch (0).msecsTo (g.authored_time ()), 1000000000);
g.set_installed_time (QDateTime ());
EXPECT_EQ (g.installed_time ().isNull (), true);
g.set_installed_time (QDateTime::fromMSecsSinceEpoch (2000000000));
EXPECT_EQ (QDateTime::fromMSecsSinceEpoch (0).msecsTo (g.installed_time ()), 2000000000);
g.add_dependency (lay::SaltGrain::Dependency ());
g.dependencies ().back ().name = "depname";
@ -105,8 +132,6 @@ TEST (1)
gg.set_doc ("blabla");
EXPECT_EQ (g == gg, false);
std::string tmp = tmp_file ();
EXPECT_EQ (g == gg, false);
g.save (tmp);
@ -269,11 +294,14 @@ TEST (4)
// That's the main test part
lay::Salt salt;
EXPECT_EQ (salt.is_empty (), true);
QSignalSpy spy (&salt, SIGNAL (collections_changed ()));
EXPECT_EQ (salt_to_string (salt), "[]");
spy.clear ();
salt.add_location (tl::to_string (tmp_dir.path ()));
EXPECT_EQ (salt.is_empty (), false);
EXPECT_EQ (spy.count (), 1);
EXPECT_EQ (salt_to_string (salt), "[a,b,c/c/v,c/u]");