Skip to content

Commit

Permalink
ver: bump to v0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvukhang committed Feb 2, 2023
2 parents 50b15a8 + ab34c93 commit 6b59985
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 119 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
- run: |
mkdir dmg
cp -a build/CanvasSync.app 'dmg/Canvas Sync.app'
mv ./deploy/mac-readme.txt dmg/README.txt
ln -s /Applications dmg/Applications
hdiutil create -volname CanvasSync \
-srcfolder dmg \
Expand Down
10 changes: 8 additions & 2 deletions clickable_tree_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ TreeModel *ClickableTreeView::model() const
void ClickableTreeView::setModel(TreeModel *model)
{
QTreeView::setModel(model);
this->setColumnHidden(TreeCol::FOLDER_ID, true);
this->resizeColumnToContents(TreeCol::REMOTE_DIR);
this->expand_tracked();
};

Expand Down Expand Up @@ -87,3 +85,11 @@ void ClickableTreeView::expand_tracked()
}
}
}

void ClickableTreeView::prettify()
{
this->resizeColumnToContents(TreeCol::REMOTE_DIR);
if (columnWidth(TreeCol::REMOTE_DIR) > this->width() * 0.6) {
setColumnWidth(TreeCol::REMOTE_DIR, this->width() * 0.6);
}
};
1 change: 1 addition & 0 deletions clickable_tree_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private slots:
void setModel(TreeModel *model);
TreeModel *model() const;
void expand_tracked();
void prettify();

signals:
void cleared(const QModelIndex &index);
Expand Down
Binary file modified deploy/export/1024.appiconset/icon_512x512@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/128.appiconset/icon_128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/16.appiconset/icon_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/256.appiconset/icon_128x128@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/256.appiconset/icon_256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/32.appiconset/icon_16x16@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/32.appiconset/icon_32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/512.appiconset/icon_256x256@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/512.appiconset/icon_512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified deploy/export/64.appiconset/icon_32x32@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions deploy/mac-readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Before running Canvas Sync for the first time, open a terminal window
and run

```
xattr -c 'Canvas Sync.app'
```

first. Otherwise there will be an error saying that this app is
developed by an unidentified developer, but that's just me, the dev.

If you've dragged-and-dropped Canvas Sync into the /Applications
folder already, simply run

```
xattr -c '/Applications/Canvas Sync.app'
```

instead. Enjoy!
111 changes: 39 additions & 72 deletions filetree.cc
Original file line number Diff line number Diff line change
@@ -1,95 +1,62 @@
#include "filetree.h"
#include <algorithm>
#include <string>

void debug(FileTree *t, int level)
{
std::string indent = std::string(2 * (level + 1), ' ');
std::cout << indent << t->id << ", " << t->name << std::endl;
for (FileTree nested : t->folders) {
debug(&nested, level + 1);
}
for (auto file : t->files) {
std::cout << indent << file.filename << std::endl;
}
// if (t->files.empty()) {
// cout << indent << "[no files]" << endl;
// }
}
void debug(FileTree *t)
{
std::cerr << "FileTree" << std::endl;
debug(t, 0);
}

void FileTree::to_string(std::string *state)
{
*state += "{(" + std::to_string(this->id) + ',' + this->name + "):";
for (FileTree nested : this->folders) {
nested.to_string(state);
}
*state += '}';
}

std::string FileTree::to_string()
{
std::string state = "";
this->to_string(&state);
return state;
}

bool compareFolderPath(Folder f1, Folder f2)
{
return f1.full_name < f2.full_name;
}

bool compareTreeName(FileTree f1, FileTree f2)
{
return f1.name < f2.name;
}

void FileTree::insert_folder(Folder *f)
{
this->insert_tree(new FileTree(f), f->full_name);
}

void FileTree::insert_folders(std::vector<Folder> folders)
{
sort(folders.begin(), folders.end(), compareFolderPath);
for (Folder f : folders)
this->insert_folder(&f);
}

void FileTree::insert_tree(FileTree *t, std::string state)
void FileTree::insert_folder(Folder &f, std::string &state)
{
size_t slash_idx = state.find('/');

// no more folders to traverse. insert here.
if (slash_idx == std::string::npos) {
this->folders.push_back(*t);
this->folders.push_back(*new FileTree(f));
return;
}

// find the next folder to go recurse into.
std::string query = state.substr(0, slash_idx);
size_t size = this->folders.size();
for (size_t i = 0; i < size; i++) {
for (size_t i = 0; i < this->folders.size(); i++) {
if (this->folders[i].name != query)
continue;
this->folders[i].insert_tree(t, state.substr(slash_idx + 1));
std::string next_state = state.substr(slash_idx + 1);
this->folders[i].insert_folder(f, next_state);
break;
}
}

void FileTree::insert_tree(FileTree *t)
void FileTree::insert_folder(Folder &f)
{
this->insert_tree(t, t->name);
insert_folder(f, f.full_name);
};

void FileTree::insert_course_tree(FileTree &t)
{
this->folders.push_back(std::move(t));
}

void FileTree::insert_trees(std::vector<FileTree> trees)
void FileTree::to_string(std::string &state)
{
sort(trees.begin(), trees.end(), compareTreeName);
for (FileTree t : trees) {
this->insert_tree(&t);
}
state += "{(" + std::to_string(this->id) + ',' + this->name + "):";
for (FileTree t : this->folders)
t.to_string(state);
state += '}';
}

std::string FileTree::to_string()
{
std::string state = "";
this->to_string(state);
return state;
}

void debug(const FileTree &t, int level)
{
std::string indent = std::string(2 * (level + 1), ' ');
std::cout << indent << t.id << ", " << t.name << std::endl;
for (FileTree nested : t.folders)
debug(nested, level + 1);
for (auto file : t.files)
std::cout << indent << file.filename << std::endl;
}
void debug(const FileTree &t)
{
std::cerr << "FileTree" << std::endl;
debug(t, 0);
}
62 changes: 41 additions & 21 deletions filetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,61 @@
#define CANVAS_SYNC_FILETREE_H

#include "types.h"
#include <vector> // for std::vector
#include <algorithm>
#include <string>
#include <vector>

class FileTree
{
public:
int id; // either course id or folder id.
std::string name;
std::vector<FileTree> folders;
std::vector<File> files;

private:
// for recursion with the public variant
void insert_tree(FileTree *, std::string);
void to_string(std::string *);
// for recursion with the public variants
void insert_folder(Folder &, std::string &);
void insert_folder_tree(FileTree &, std::string &);
void to_string(std::string &);

// constructors
public:
FileTree()
{
this->id = 0;
this->name = "root";
}
FileTree() : id(0), name("root"){};
FileTree(const int id, const char *n) : id(id), name(n){};
FileTree(const int id, const std::string n) : id(id), name(n){};
FileTree(const Folder *f) : id(f->id), name(f->name){};
FileTree(const Folder &f) : id(f.id), name(f.name){};
FileTree(const Course *c) : id(c->id), name(c->name){};
FileTree(const Course *c, const std::vector<Folder> f)
: id(c->id), name(c->name)
FileTree(const Course *c, std::vector<Folder> &f) : id(c->id), name(c->name)
{
this->insert_folders(f);
};
int id; // either course id or folder id.
std::string name;
std::vector<FileTree> folders;
std::vector<File> files;
void insert_folder(Folder *);
void insert_folders(std::vector<Folder>);
void insert_tree(FileTree *);
void insert_trees(std::vector<FileTree>);
void insert_file(File *);

// insertions
void insert_folder(Folder &);
void insert_course_tree(FileTree &);

// iterated versions
void insert_folders(std::vector<Folder> &folders)
{
sort(folders.begin(), folders.end(),
[](Folder &a, Folder &b) { return a.full_name < b.full_name; });
for (Folder f : folders)
this->insert_folder(f);
}
void insert_course_trees(std::vector<FileTree> &t)
{
sort(t.begin(), t.end(),
[](FileTree &a, FileTree &b) { return a.name < b.name; });
for (FileTree t : t)
this->insert_course_tree(t);
};

public:
// debug tools
std::string to_string();
};
void debug(FileTree *);
void debug(const FileTree &);

#endif
8 changes: 4 additions & 4 deletions mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ void MainWindow::course_folders_fetched(const Course &c)
this->folder_names.insert(std::pair(f.id, f.full_name));
}
this->course_trees.push_back(t);
this->refresh_tree();
refresh_tree_data();
ui->treeView->prettify();
tree_mtx.unlock();
ui->guideText->setHidden(!this->gather_tracked().empty());
}
Expand Down Expand Up @@ -335,18 +336,17 @@ void MainWindow::disable_fetch(const QString &s)
ui->pushButton_fetch->setEnabled(false);
}

void MainWindow::refresh_tree()
void MainWindow::refresh_tree_data()
{
TreeModel *model = newTreeModel();
FileTree t;
t.insert_trees(this->course_trees);
t.insert_course_trees(this->course_trees);
insert(model->item(0), &t, &settings);
ui->treeView->setModel(model);
}

void MainWindow::set_auth_state(bool authenticated)
{
qDebug() << "MainWindow::set_auth_state -> " << authenticated;
this->authenticated = authenticated;
if (authenticated) {
this->enable_pull();
Expand Down
8 changes: 4 additions & 4 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class MainWindow : public QMainWindow
bool has_network_err(QNetworkReply *r)
{
if (r->error() != QNetworkReply::NoError) {
qDebug() << "Network Error: " << r->errorString();
qDebug() << "Error Type: " << r->error();
qDebug() << "from url:" << r->url();
qDebug() << "Network Error: " << r->errorString() << '\n'
<< "Error Type: " << r->error() << '\n'
<< "from url:" << r->url();
return true;
}
return false;
Expand Down Expand Up @@ -97,7 +97,7 @@ private slots:
void disable_pull(const QString & = "Pulling...");
void enable_fetch(const QString & = "Fetch");
void disable_fetch(const QString & = "Fetching...");
void refresh_tree();
void refresh_tree_data();
void set_auth_state(bool);
void show_updates();
void check_auth(const QString &token);
Expand Down
11 changes: 1 addition & 10 deletions tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ void resolve_all_folders(TreeItem *item, fs::path *local_base_dir,
{
std::string local_dir = get_local_dir(*item).toStdString();

if (!cwd->empty() && !local_dir.empty()) {
qDebug() << "NOT SUPPOSED TO REACH HERE";
qDebug() << "resolve_all_folders:: cwd and local_dir are both populated.";
}

fs::path new_cwd;
fs::path new_base = *local_base_dir;

Expand Down Expand Up @@ -161,9 +156,5 @@ void on_all_children(TreeItem *item, ItemOperator func)

TreeModel *newTreeModel()
{
auto headers = QStringList() << "canvas folder"
<< "local folder"
<< "id";
TreeModel *model = new TreeModel(headers);
return model;
return new TreeModel({"canvas folder", "local folder"});
}
6 changes: 0 additions & 6 deletions tree_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ bool TreeModel::removeColumns(int position, int columns,
try {
rootItem->removeColumns(position, columns);
} catch (std::out_of_range &e) {
qDebug() << e.what();
endRemoveColumns();
return false;
}
Expand All @@ -399,7 +398,6 @@ bool TreeModel::removeRows(int position, int rows, const QModelIndex &parent)
try {
parentItem->removeRows(position, rows);
} catch (std::out_of_range &e) {
qDebug() << e.what();
endRemoveRows();
return false;
}
Expand All @@ -419,7 +417,6 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value,
try {
item->setData(index.column(), value);
} catch (std::out_of_range &e) {
qDebug() << e.what();
return false;
}
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
Expand All @@ -436,7 +433,6 @@ bool TreeModel::setHeaderData(int section, Qt::Orientation orientation,
try {
rootItem->setData(section, value);
} catch (std::out_of_range &e) {
qDebug() << e.what();
return false;
}

Expand All @@ -451,7 +447,6 @@ bool TreeModel::insertColumns(int position, int columns,
try {
rootItem->insertColumns(position, columns);
} catch (std::out_of_range &e) {
qDebug() << e.what();
endInsertColumns();
return false;
}
Expand All @@ -470,7 +465,6 @@ bool TreeModel::insertRows(int position, int rows, const QModelIndex &parent)
try {
parentItem->insertRows(position, rows, rootItem->columnCount());
} catch (std::out_of_range &e) {
qDebug() << e.what();
endInsertRows();
return false;
}
Expand Down

0 comments on commit 6b59985

Please sign in to comment.