Skip to content

Commit

Permalink
session slots; more shortcuts; better F1 help screen
Browse files Browse the repository at this point in the history
  • Loading branch information
siavash119 committed May 18, 2018
1 parent 0956e63 commit 38aefd6
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 77 deletions.
5 changes: 3 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ Chan *twoChHkAPI = new TwoChHk();

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("qtchan");
QCoreApplication::setApplicationName("qtchan");
//QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//QApplication::setAttribute(QT_SCALE_FACTOR,"1.4");
//qputenv("QT_SCALE_FACTOR","0.2");
QApplication a(argc, argv);
QFont font = QGuiApplication::font();
QSettings settings(QSettings::IniFormat,QSettings::UserScope,"qtchan","qtchan");
font.setPointSize(settings.value("fontSize",14).toInt());
Expand All @@ -37,6 +37,7 @@ int main(int argc, char *argv[])
/*NotificationTray t;
t.setIcon(QIcon(":/icons/icon_22x22.png"));
t.show();*/
w.loadSession();
QString sessionSlot = settings.value("sessionSlot","0").toString();
w.loadSession(sessionSlot);
return a.exec();
}
61 changes: 44 additions & 17 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ void MainWindow::setShortcuts()
addShortcut(QKeySequence("Ctrl+u"),this,&MainWindow::toggleAutoUpdate);
addShortcut(QKeySequence("Ctrl+e"),this,&MainWindow::toggleAutoExpand);

//TODO select session saves slots
addShortcut(Qt::Key_F10,this,&MainWindow::saveSession);

//TODO select session saves slots
addShortcut(Qt::Key_F12,this,&MainWindow::loadSession);

addShortcut(QKeySequence("ctrl+o"),this,&MainWindow::openExplorer);

addShortcut(QKeySequence::ZoomOut,this,[=](){
Expand Down Expand Up @@ -183,7 +177,7 @@ void MainWindow::setShortcuts()

ui->actionSave->setShortcut(QKeySequence("Ctrl+s"));
ui->actionSave->setShortcutContext(Qt::ApplicationShortcut);
connect(ui->actionSave,&QAction::triggered,this,&MainWindow::saveSession);
connect(ui->actionSave,&QAction::triggered,[=]{saveSession();});

ui->actionReload->setShortcut(QKeySequence("Ctrl+r"));
connect(ui->actionReload,&QAction::triggered,[=]{
Expand Down Expand Up @@ -218,7 +212,6 @@ void MainWindow::setShortcuts()
filter.loadFilterFile2();
emit reloadFilters();
});

addShortcut(QKeySequence("ctrl+f"),this,[=]{
TreeItem *item = model->getItem(selectionModel->currentIndex());
if(!item) return;
Expand Down Expand Up @@ -253,9 +246,41 @@ void MainWindow::setShortcuts()
addShortcut(Qt::Key_F4,this,[=]{
if(QWidget *temp = currentWidget()) temp->setFocus();
});
addShortcut(Qt::Key_F6,this,&MainWindow::focusBar);
//addShortcut(Qt::Key_F6,this,&MainWindow::focusBar);
addShortcut(Qt::Key_F8,&aTab,&ArchiveTab::show);

//session shortcuts
for(int i=Qt::Key_F1, j=0; i<=Qt::Key_F4; i++, j++){
QAction *saveShortcut = new QAction(this);
saveShortcut->setShortcut(QKeySequence(Qt::ControlModifier+i));
connect(saveShortcut, &QAction::triggered,[=]{
qDebug() << "saving shortcut";
saveSession(QString::number(j));
});
this->addAction(saveShortcut);
QAction *loadShortcut = new QAction(this);
loadShortcut->setShortcut(QKeySequence(Qt::ShiftModifier+i));
connect(loadShortcut, &QAction::triggered,[=]{
loadSession(QString::number(j));
});
this->addAction(loadShortcut);
}
addShortcut(Qt::Key_F5,this,[=]{saveSession();});
addShortcut(Qt::Key_F6,this,[=]{loadSession();});
addShortcut(QKeySequence("ctrl+F5"),this,[=]{
QSettings settings(QSettings::IniFormat,QSettings::UserScope,"qtchan","qtchan");
int slot = settings.value("sessionFileSlot",0).toInt();
if(--slot == 0) slot = 9;
settings.setValue("sessionFileSlot",slot);
qDebug() << "current session slot:" << slot;
});
addShortcut(QKeySequence("ctrl+F6"),this,[=]{
QSettings settings(QSettings::IniFormat,QSettings::UserScope,"qtchan","qtchan");
int slot = settings.value("sessionFileSlot",0).toInt();
if(++slot == 10) slot = 0;
settings.setValue("sessionFileSlot",slot);
qDebug() << "current session slot:" << slot;
});
}

void MainWindow::showHelp(){
Expand Down Expand Up @@ -542,20 +567,22 @@ void MainWindow::focusBar()
ui->navBar->selectAll();
}

void MainWindow::saveSession()
void MainWindow::saveSession(QString slot)
{
qDebug().noquote() << "Saving session.";
QSettings settings(QSettings::IniFormat,QSettings::UserScope,"qtchan","qtchan");
QString sessionFile = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/qtchan/" + settings.value("sessionFile","session.txt").toString();
qDebug() << settings.value("sessionFile","session.txt").toString();
model->saveSessionToFile(sessionFile,ui->treeView->currentIndex());
if(slot.isEmpty()) slot = settings.value("sessionSlot","0").toString();
QString sessionPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/qtchan/sessions/";
QDir().mkpath(sessionPath);
QString sessionFile = sessionPath + settings.value("sessionFile","session").toString();
model->saveSessionToFile(sessionFile,slot,ui->treeView->currentIndex());
}

void MainWindow::loadSession()
void MainWindow::loadSession(QString slot)
{
QSettings settings(QSettings::IniFormat,QSettings::UserScope,"qtchan","qtchan");
QString sessionFile = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/qtchan/" + settings.value("sessionFile","session.txt").toString();
QModelIndex qmi = model->loadSessionFromFile(sessionFile);
if(slot.isEmpty()) slot = settings.value("sessionSlot","0").toString();
QString sessionFile = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/qtchan/sessions/" + settings.value("sessionFile","session").toString();
QModelIndex qmi = model->loadSessionFromFile(sessionFile,slot);
selectionModel->setCurrentIndex(qmi,QItemSelectionModel::ClearAndSelect);
ui->treeView->setCurrentIndex(qmi);
}
4 changes: 2 additions & 2 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public slots:
void focusBar();
TreeItem *loadFromSearch(QString query, QString display, TreeItem *childOf, bool select = false);
TreeItem *onNewThread(QWidget *parent, Chan *api, QString board, QString thread, QString display, TreeItem *childOf);
void saveSession();
void loadSession();
void saveSession(QString slot = QString());
void loadSession(QString slot = QString());
void prevTab();
void nextTab();
void prevParent();
Expand Down
101 changes: 66 additions & 35 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -382,43 +382,74 @@
<property name="lineWidth">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="helpLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>0</width>
<height>796</height>
</rect>
</property>
<property name="bottomMargin">
<number>0</number>
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<widget class="QLabel" name="help">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
<layout class="QVBoxLayout" name="helpLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="help">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</widget>
Expand Down
1 change: 0 additions & 1 deletion netcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ void netController::refreshManagers(){
fileManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
captchaManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
}

//std::vector<BoardTab*> bts;
//std::vector<Tab> tabs;
//std::vector<QWidget*> tabs;
29 changes: 21 additions & 8 deletions readstartup.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
<p>welcome to <a href="https://github.com/siavash119/qtchan">qtchan</a>. here is some useful info</p>
<ul>
<h3>navigation</h3>
<li>F1 shows this help</li>
<li>ctrl+l opens up the nav bar</li>
<li>you can type g or g/boardnum or /g/ or https://boards.4chan... etc.</li>
<li>g for first page, /g/ for catalog, g/search to get catalog and search</li>
<li>o opens thread/image at top of view (expand the tree if you don't see the new tab in the treeview)</li>
<li>F3 focuses the tree, F4 focuses the content</li>
<li>ctrl+tab ctrl+shift+tab, ctrl+1-4 to switch tabs</li>
<li>ctrl+w or delete to close tab</li>
<li>ctrl+q to quit</li>
<h3>pages</h3>
<li>#j and #k scroll by post(e.g. 5j, k)</li>
<li>#h and #l scroll by replies to (You)</li>
<li>#G puts scrollbar at percent (e.g. G for bottom, 0G for top, 50G for 50%)</li>
<li>ctrl+w (ctrl+f4 on windows) or delete to close tab</li>
<li>ctrl+p opens settings-ctrl+tab ctrl+shift+tab, ctrl+1-4 to switch tabs</li>
<li>ctrl+f to search and filter</li>
<li>r manually refreshes thread</li>
<li>q opens up post form, shift+enter to post from there</li>
<li>focus the bottom lineEdit to load captcha; press enter to verify/reload</li>
<li>ctrl+o opens current save folder in default file manager</li>
<h3>posting</h3>
<li>q opens up post form, shift+enter to post from postform</li>
<li>focus the bottom lineEdit to load captcha; answer pictures like the numpad (e.g. 135)
<li>press enter in answer field to verify/reload captcha</li>
<li>e expands all images and auto expands future posts on current tab</li>
<h3>settings</h3>
<li>ctrl+p opens settings</li>
<li>ctrl+plus/minus to zoom in/zoom out text</li>
<li>ctrl+9/0 to scale down/up images</li>
<li>ctrl+q to quit</li>
<li>F9 toggles notification view</li>
<li>F10 saves tree state (it'll also save on exit)</li>
<li>F11 hides menubar</li>
<li>F11 hides menubar (currently disables some shortcuts)</li>
<h3>sessions</h3>
<li>F5 saves tree session(it'll also save on exit)</li>
<li>F6 loads tree session</li>
<li>ctrl+F1-F4 saves tree session to slots (0-3)</li>
<li>shift+F1-F4 loads tree session from slots (0-3)</li>
<li>ctrl+F5-F6 selects prev/next session slot (0-9)</li>
<h3>other</h3>
<li>F9 toggles notification view (unfinished)</li>
<li>if you have mpv, g opens all the images/videos in the thread.</li>
</ul>
<p>there are more shortcuts; look at the source for now for info.</p>
Expand Down
4 changes: 2 additions & 2 deletions threadtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ void ThreadTab::setShortcuts()
//&helper,&ThreadTabHelper::getPosts,Qt::DirectConnection);
this->addAction(refresh);

QAction *focusBar = new QAction(this);
/*QAction *focusBar = new QAction(this);
focusBar->setShortcut(Qt::Key_F6);
connect(focusBar,&QAction::triggered,mw,&MainWindow::focusBar);
this->addAction(focusBar);
this->addAction(focusBar);*/

QAction *selectPost = new QAction(this);
selectPost->setShortcut(Qt::Key_O);
Expand Down
3 changes: 1 addition & 2 deletions threadtabhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ void ThreadTabHelper::getPostsFinished() {
}
QVariant fromCache = reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute);
if(fromCache.toBool()){
qDebug().noquote().nospace() << "got " << title << ": returned cache";
return;
qDebug().noquote().nospace() << "got " << title << " from cache";
}
QByteArray rep = reply->readAll();
reply->deleteLater();
Expand Down
14 changes: 8 additions & 6 deletions treemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@ QModelIndex TreeModel::getIndex(TreeItem *item) const
return createIndex(item->row(),0,item);
}

void TreeModel::saveSessionToFile(QString fileName, QModelIndex ind)
void TreeModel::saveSessionToFile(QString fileName, QString slot, QModelIndex ind)
{
QFile data(fileName);
if(!data.open(static_cast<QFile::OpenMode>(QFile::WriteOnly | QFile::Truncate))){
qDebug().noquote().nospace() << "saving session " << fileName << slot;
QFile session(fileName+slot);
if(!session.open(static_cast<QFile::OpenMode>(QFile::WriteOnly | QFile::Truncate))){
qDebug().noquote() << "unable to open session file" << fileName;
return;
}
QTextStream out(&data);
QTextStream out(&session);
QList<TreeItem*> parents;
QList<int> lines;
parents << root;
Expand Down Expand Up @@ -284,9 +285,10 @@ void TreeModel::saveSessionToFile(QString fileName, QModelIndex ind)
out << indexString << endl;
}

QModelIndex TreeModel::loadSessionFromFile(QString sessionFile)
QModelIndex TreeModel::loadSessionFromFile(QString fileName, QString slot)
{
QFile session(sessionFile);
qDebug().noquote().nospace() << "loading session " << fileName << slot;
QFile session(fileName+slot);
session.open(QFile::ReadOnly);
QTextStream in(&session);
QString line;
Expand Down
4 changes: 2 additions & 2 deletions treemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class TreeModel : public QAbstractItemModel
QModelIndex getIndex(TreeItem *item) const;
TreeItem *getItem(const QModelIndex &index) const;

void saveSessionToFile(QString filename, QModelIndex ind = QModelIndex());
QModelIndex loadSessionFromFile(QString filename);
void saveSessionToFile(QString filename, QString slot, QModelIndex ind = QModelIndex());
QModelIndex loadSessionFromFile(QString filename, QString slot);
void addTab(TreeItem *child, TreeItem *parent, bool select);
void removeChildren(QModelIndex ind);
QList<int> fullIndex(QModelIndex ind);
Expand Down

0 comments on commit 38aefd6

Please sign in to comment.