Browse Source

fridgegrid: creating subfolder in documents for data and templates

tags/1.3
Sven Oliver Moll 10 months ago
parent
commit
db886cb986

+ 68
- 0
src/fridgegrid/DocumentsDir.cpp View File

@@ -0,0 +1,68 @@
/*
* src/fridgegrid/MainWindow.cpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

/* class declaration */
#include "DocumentsDir.hpp"

/* system headers */

/* Qt headers */
#include <QCoreApplication>
#include <QFileInfoList>
#include <QStandardPaths>

/* local library headers */

/* local headers */


DocumentsDir::DocumentsDir()
: mDir()
{
QDir templatesDir( getTemplatesDirName() );

if( !templatesDir.exists() )
{
generateTemplateDir();
}
}


QFileInfoList DocumentsDir::getTemplates() const
{
return QDir( getTemplatesDirName() ).entryInfoList( QStringList("*.xml"), QDir::Files );
}


QString DocumentsDir::getTemplatesDirName() const
{
return QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ) +
"/" + QCoreApplication::applicationName() + "/Templates";
}


void DocumentsDir::generateTemplateDir()
{
QFileInfoList fil( QDir(":/templates/").entryInfoList() );
QDir templatesDir( getTemplatesDirName() );

if( !templatesDir.mkpath( "." ) )
{
return;
}

foreach( const QFileInfo &fi, fil )
{
QString srcFile( fi.absoluteFilePath() );
QString destFile( templatesDir.absoluteFilePath( fi.fileName() ) );
if( QFile::copy( srcFile, destFile ) )
{
QFile::setPermissions( destFile, QFile::permissions( destFile ) | QFile::WriteUser );
}
}
}

+ 46
- 0
src/fridgegrid/DocumentsDir.hpp View File

@@ -0,0 +1,46 @@
/*
* src/fridgegrid/MainWindow.hpp
* written by Sven Oliver Moll
*
* distributed under the terms of the GNU General Public License (GPL)
* available at http://www.gnu.org/licenses/gpl.html
*/

#ifndef DOCUMENTSDIR_HPP
#define DOCUMENTSDIR_HPP DOCUMENTSDIR_HPP

/* base class */

/* system headers */

/* Qt headers */
#include <QDir>

/* local library headers */

/* local headers */

/* forward declaration of Qt classes */

/* forward declaration of local classes */




class DocumentsDir
{
public:
DocumentsDir();

QFileInfoList getTemplates() const;

private:
DocumentsDir( const DocumentsDir &that );
DocumentsDir &operator=( const DocumentsDir &that );

QDir mDir;
QString getTemplatesDirName() const;
void generateTemplateDir();
};

#endif // DOCUMENTSDIR_HPP

+ 6
- 4
src/fridgegrid/MainWindow.cpp View File

@@ -30,6 +30,7 @@
/* local library headers */

/* local headers */
#include "DocumentsDir.hpp"
#include "DragWidget.hpp"

#include <QtDebug>
@@ -43,6 +44,7 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
, mpDragWidget( new DragWidget( mpSplitter ) )
, mLastFilenames()
{
DocumentsDir docDir;
QCommonStyle style;
QSettings settings;
QMenu *templateMenu( new QMenu( this ) );
@@ -83,14 +85,14 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
action = new QAction( style.standardIcon( QStyle::SP_FileDialogNewFolder ), "New Grid", this );
action->setShortcuts( QKeySequence::New );
action->setMenu( templateMenu );
action->setVisible(true);
action->setVisible( true );
toolBar->addAction( action );

// just want to tell the associated button, that we always want the menu list
// can't this be done easier?
{
QList<QWidget*> wl( action->associatedWidgets() );
foreach(QWidget *w, wl)
foreach( QWidget *w, wl )
{
QToolButton *b = qobject_cast<QToolButton*>(w);
if( b )
@@ -103,8 +105,8 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
QSignalMapper *signalMapper = new QSignalMapper( this );
connect( signalMapper, SIGNAL(mapped(QString)),
mpDragWidget, SLOT(load(QString)) );
QFileInfoList fil( QDir(":/templates/").entryInfoList() );
foreach( const QFileInfo &fi, fil )
foreach( const QFileInfo &fi, docDir.getTemplates() )
{
action = templateMenu->addAction( fi.baseName().replace('_',' ') );
action->setData( fi.filePath() );

+ 3
- 0
src/fridgegrid/fridgegrid.pro View File

@@ -10,6 +10,9 @@ RESOURCES += ../resources/FridgeGrid.qrc
#TRANSLATIONS += Translations/otts_de.ts
CODECFORTR += UTF-8

SOURCES += DocumentsDir.cpp
HEADERS += DocumentsDir.hpp

SOURCES += DragLabel.cpp
HEADERS += DragLabel.hpp


Loading…
Cancel
Save