Fix #21 Add filechooser on startup
Add a fileview class that shows the local file system. User can choose the desired storage folder there.master
parent
05109b780e
commit
251fe28688
|
@ -57,10 +57,13 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp
|
|||
${CMAKE_SOURCE_DIR}/src/ui/webDAVView/webDAVView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/webDAVView/webDAVViewEntry.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/loginView/loginView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/fileView/fileView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/fileView/fileViewEntry.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/util.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/log.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/api/webDAV.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/api/sqliteConnector.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/api/fileBrowser.cpp
|
||||
)
|
||||
|
||||
add_executable(Nextcloud.app ${SOURCES})
|
||||
|
@ -74,6 +77,7 @@ include_directories(
|
|||
${CMAKE_SOURCE_DIR}/src/ui/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listView/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/webDAVView/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/fileView/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/loginView/
|
||||
${CMAKE_SOURCE_DIR}/src/api/
|
||||
)
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
//
|
||||
//------------------------------------------------------------------
|
||||
// fileBrowser.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 29.07.2022
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "fileBrowser.h"
|
||||
#include "inkview.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
|
||||
FileBrowser::FileBrowser()
|
||||
{
|
||||
}
|
||||
|
||||
//TODO let the user choose if file or only folders, create API class or do inside here?
|
||||
std::vector<FileItem> FileBrowser::getFileStructure(const std::string &path)
|
||||
{
|
||||
//get local files, https://stackoverflow.com/questions/306533/how-do-i-get-a-list-of-files-in-a-directory-in-c
|
||||
DIR *dir;
|
||||
class dirent *ent;
|
||||
class stat st;
|
||||
string localPath = path;
|
||||
std::vector<FileItem> items;
|
||||
|
||||
if(localPath.back() != '/')
|
||||
localPath = localPath + '/';
|
||||
|
||||
FileItem temp;
|
||||
temp.path = localPath.substr(0,localPath.find_last_of('/'));
|
||||
temp.path = temp.path.substr(0,temp.path.find_last_of('/'));
|
||||
if(temp.path.empty())
|
||||
temp.path = "/";
|
||||
temp.name = "..";
|
||||
temp.type = Type::FFOLDER;
|
||||
items.push_back(temp);
|
||||
|
||||
if (iv_access(localPath.c_str(), R_OK) == 0)
|
||||
{
|
||||
dir = opendir(localPath.c_str());
|
||||
while ((ent = readdir(dir)) != NULL)
|
||||
{
|
||||
const string fileName = ent->d_name;
|
||||
|
||||
|
||||
if (fileName[0] == '.')
|
||||
continue;
|
||||
|
||||
const string fullFileName = localPath + fileName;
|
||||
|
||||
if (stat(fullFileName.c_str(), &st) == -1)
|
||||
continue;
|
||||
|
||||
FileItem temp;
|
||||
if ((st.st_mode & S_IFDIR) != 0)
|
||||
{
|
||||
temp.path = fullFileName;
|
||||
temp.name = fullFileName.substr(fullFileName.find_last_of("/") + 1, fullFileName.length());
|
||||
temp.type = Type::FFOLDER;
|
||||
temp.path += '/';
|
||||
items.push_back(temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
temp.path = fullFileName;
|
||||
temp.name = fullFileName.substr(fullFileName.find_last_of("/") + 1, fullFileName.length());
|
||||
temp.type = Type::FFILE;
|
||||
temp.path += '/';
|
||||
items.push_back(temp);
|
||||
*/
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
return items;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
//------------------------------------------------------------------
|
||||
// fileBrowser.h
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 29.07.2022
|
||||
// Description: Interface to the filesystem fo the PB
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifndef FILEBROWSER
|
||||
#define FILEBROWSER
|
||||
|
||||
#include "fileModel.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class FileBrowser
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates a new FileBrowser object
|
||||
*
|
||||
*/
|
||||
FileBrowser();
|
||||
|
||||
void test();
|
||||
|
||||
std::vector<FileItem> getFileStructure(const std::string &path);
|
||||
|
||||
|
||||
private:
|
||||
std::string _currentLocation;
|
||||
|
||||
};
|
||||
#endif
|
|
@ -9,17 +9,17 @@
|
|||
#ifndef FILEMODEL
|
||||
#define FILEMODEL
|
||||
|
||||
//#include "model.h"
|
||||
#include "model.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
enum Type
|
||||
{
|
||||
FOLDER,
|
||||
FIL
|
||||
FFOLDER,
|
||||
FFILE
|
||||
};
|
||||
|
||||
struct File : Entry{
|
||||
struct FileItem : Entry{
|
||||
std::string name;
|
||||
std::string path;
|
||||
Type type;
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
using std::vector;
|
||||
|
||||
FileView::FileView(const irect &contentRect, const vector<File> &files, int page) : ListView(contentRect, page)
|
||||
FileView::FileView(const irect &contentRect, const vector<FileItem> &files, int page) : ListView(contentRect, page)
|
||||
{
|
||||
auto pageHeight = 0;
|
||||
auto contentHeight = _contentRect->h - _footerHeight;
|
||||
auto contentHeight = _contentRect.h - _footerHeight;
|
||||
auto entrycount = files.size();
|
||||
|
||||
_entries.reserve(entrycount);
|
||||
|
@ -26,13 +26,13 @@ FileView::FileView(const irect &contentRect, const vector<File> &files, int page
|
|||
auto i = 0;
|
||||
while (i < entrycount)
|
||||
{
|
||||
auto entrySize = TextRectHeight(contentRect->w, files.at(i).name.c_str(), 0) + 2.5 * _entryFontHeight;
|
||||
auto entrySize = TextRectHeight(contentRect.w, files.at(i).name.c_str(), 0) + 2.5 * _entryFontHeight;
|
||||
if ((pageHeight + entrySize) > contentHeight)
|
||||
{
|
||||
pageHeight = 0;
|
||||
_page++;
|
||||
}
|
||||
irect rect = iRect(_contentRect->x, _contentRect->y + pageHeight, _contentRect->w, entrySize, 0);
|
||||
irect rect = iRect(_contentRect.x, _contentRect.y + pageHeight, _contentRect.w, entrySize, 0);
|
||||
|
||||
_entries.emplace_back(std::unique_ptr<FileViewEntry>(new FileViewEntry(_page, rect, files.at(i))));
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ public:
|
|||
* @param Items items that shall be shown in the listview
|
||||
* @param page page that is shown, default is 1
|
||||
*/
|
||||
FileView(const irect &contentRect, const std::vector<File> &files, int page = 1);
|
||||
FileView(const irect &contentRect, const std::vector<FileItem> &files, int page = 1);
|
||||
|
||||
File &getCurrentEntry() { return getEntry(_selectedEntry); };
|
||||
FileItem &getCurrentEntry() { return getEntry(_selectedEntry); };
|
||||
|
||||
File &getEntry(int entryID) { return std::dynamic_pointer_cast<FileViewEntry>(_entries.at(entryID))->get(); };
|
||||
FileItem &getEntry(int entryID) { return std::dynamic_pointer_cast<FileViewEntry>(_entries.at(entryID))->get(); };
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
FileViewEntry::FileViewEntry(int page, const irect &position, const File &entry) : ListViewEntry(page, position), _entry(entry)
|
||||
FileViewEntry::FileViewEntry(int page, const irect &position, const FileItem &entry) : ListViewEntry(page, position), _entry(entry)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ void FileViewEntry::draw(const ifont *entryFont, const ifont *entryFontBold, int
|
|||
//DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, _entry.name.c_str(), ALIGN_LEFT);
|
||||
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, _entry.path.c_str(), ALIGN_LEFT);
|
||||
std::string type = "File";
|
||||
if(_entry.type == Type::FOLDER)
|
||||
if(_entry.type == Type::FFOLDER)
|
||||
type = "Folder";
|
||||
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, type.c_str(), ALIGN_RIGHT);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
* @param Rect area of the screen the item is positioned
|
||||
* @param entry entry that shall be drawn
|
||||
*/
|
||||
FileViewEntry(int page, const irect &position, const File &entry);
|
||||
FileViewEntry(int page, const irect &position, const FileItem &entry);
|
||||
|
||||
/**
|
||||
* draws the FileViewEntry to the screen
|
||||
|
@ -33,9 +33,9 @@ public:
|
|||
*/
|
||||
void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) override;
|
||||
|
||||
File &get() { return _entry; };
|
||||
FileItem &get() { return _entry; };
|
||||
|
||||
private:
|
||||
File _entry;
|
||||
FileItem _entry;
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue