├── requirements.txt ├── src ├── build │ └── settings │ │ ├── mac.json │ │ ├── linux.json │ │ └── base.json └── main │ ├── icons │ ├── Icon.ico │ ├── base │ │ ├── 16.png │ │ ├── 24.png │ │ ├── 32.png │ │ ├── 48.png │ │ └── 64.png │ ├── mac │ │ ├── 128.png │ │ ├── 256.png │ │ ├── 512.png │ │ └── 1024.png │ ├── linux │ │ ├── 1024.png │ │ ├── 128.png │ │ ├── 256.png │ │ └── 512.png │ └── README.md │ └── python │ ├── cli.py │ ├── main.py │ ├── buttonTray.py │ ├── center.py │ ├── sidebar.py │ └── database.py ├── gifs ├── liszt_buttons.gif ├── liszt_add_and_move.gif └── liszt_modify_tasks.gif ├── .gitignore ├── README.md ├── .github └── workflows │ └── main.yml └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | PySide2==5.15.0 2 | fbs==0.9.0 3 | -------------------------------------------------------------------------------- /src/build/settings/mac.json: -------------------------------------------------------------------------------- 1 | { 2 | "mac_bundle_identifier": "" 3 | } -------------------------------------------------------------------------------- /gifs/liszt_buttons.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/gifs/liszt_buttons.gif -------------------------------------------------------------------------------- /src/main/icons/Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/Icon.ico -------------------------------------------------------------------------------- /src/main/icons/base/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/base/16.png -------------------------------------------------------------------------------- /src/main/icons/base/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/base/24.png -------------------------------------------------------------------------------- /src/main/icons/base/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/base/32.png -------------------------------------------------------------------------------- /src/main/icons/base/48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/base/48.png -------------------------------------------------------------------------------- /src/main/icons/base/64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/base/64.png -------------------------------------------------------------------------------- /src/main/icons/mac/128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/mac/128.png -------------------------------------------------------------------------------- /src/main/icons/mac/256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/mac/256.png -------------------------------------------------------------------------------- /src/main/icons/mac/512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/mac/512.png -------------------------------------------------------------------------------- /gifs/liszt_add_and_move.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/gifs/liszt_add_and_move.gif -------------------------------------------------------------------------------- /gifs/liszt_modify_tasks.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/gifs/liszt_modify_tasks.gif -------------------------------------------------------------------------------- /src/main/icons/linux/1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/linux/1024.png -------------------------------------------------------------------------------- /src/main/icons/linux/128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/linux/128.png -------------------------------------------------------------------------------- /src/main/icons/linux/256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/linux/256.png -------------------------------------------------------------------------------- /src/main/icons/linux/512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/linux/512.png -------------------------------------------------------------------------------- /src/main/icons/mac/1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwandaPinocle/Liszt/HEAD/src/main/icons/mac/1024.png -------------------------------------------------------------------------------- /src/build/settings/linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "categories": "Utility;", 3 | "description": "", 4 | "author_email": "", 5 | "url": "" 6 | } -------------------------------------------------------------------------------- /src/build/settings/base.json: -------------------------------------------------------------------------------- 1 | { 2 | "app_name": "Liszt", 3 | "author": "Adpolican", 4 | "main_module": "src/main/python/main.py", 5 | "version": "0.0.0" 6 | } -------------------------------------------------------------------------------- /src/main/python/cli.py: -------------------------------------------------------------------------------- 1 | from database import Database 2 | 3 | if __name__ == '__main__': 4 | db = Database() 5 | while True: 6 | command = input(f'({db.runCommand("where")})> ') 7 | if command == 'exit': 8 | break 9 | try: 10 | print(db.runCommand(command)) 11 | except Exception as e: 12 | print('Invalid input') 13 | print(e) 14 | -------------------------------------------------------------------------------- /src/main/icons/README.md: -------------------------------------------------------------------------------- 1 | ![Sample app icon](linux/128.png) 2 | 3 | This directory contains the icons that are displayed for your app. Feel free to 4 | change them. 5 | 6 | The difference between the icons on Mac and the other platforms is that on Mac, 7 | they contain a ~5% transparent margin. This is because otherwise they look too 8 | big (eg. in the Dock or in the app switcher). 9 | 10 | You can create Icon.ico from the .png files with 11 | [an online tool](http://icoconvert.com/Multi_Image_to_one_icon/). -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Liszt 3 | ![license](https://img.shields.io/badge/license-GPL%203.0-brightgreen) 4 | 5 | Liszt is a simple and distraction-free tool for creating and managing lists. 6 | Intended as a replacement for Trello, you can set due dates, attach info to cards, and even automate tasks at the push of a button. 7 | GUI is made with Qt using Pyside2 and all data is stored in a single Sqlite3 db file. 8 | 9 | To run, just type 10 | ``` 11 | python3 main.py 12 | ``` 13 | 14 | # Features 15 | ## Create and move cards 16 | ![create cards](https://github.com/rwandaPinocle/Liszt/raw/master/gifs/liszt_add_and_move.gif) 17 | 18 | ## Set due dates and add details 19 | ![set due dates and add details](https://github.com/rwandaPinocle/Liszt/raw/master/gifs/liszt_modify_tasks.gif) 20 | 21 | ## Automate tasks with command buttons 22 | ![automate tasks with buttons](https://raw.githubusercontent.com/rwandaPinocle/Liszt/master/gifs/liszt_buttons.gif) 23 | 24 | # Requirements 25 | The only dependency is Qt via Pyside2. 26 | You can install with 27 | ``` 28 | pip3 install -r requirements.txt 29 | ``` 30 | 31 | 32 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the action will run. 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the master branch 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v2 27 | 28 | # Runs a single command using the runners shell 29 | - name: Run a one-line script 30 | run: echo Hello, world! 31 | 32 | # Runs a set of commands using the runners shell 33 | - name: Run a multi-line script 34 | run: | 35 | echo Add other actions to build, 36 | echo test, and deploy your project. 37 | -------------------------------------------------------------------------------- /src/main/python/main.py: -------------------------------------------------------------------------------- 1 | # This Python file uses the following encoding: utf-8 2 | import sys 3 | import csv 4 | import io 5 | 6 | from fbs_runtime.application_context.PySide2 import ApplicationContext 7 | from PySide2.QtWidgets import ( 8 | QApplication, 9 | QMainWindow, 10 | QLabel, 11 | QVBoxLayout, 12 | QDockWidget, 13 | QWidget, 14 | QTableView, 15 | QHBoxLayout, 16 | QVBoxLayout, 17 | QTreeView, 18 | QListView, 19 | QLineEdit, 20 | QAbstractItemView, 21 | QPushButton, 22 | ) 23 | from PySide2.QtCore import ( 24 | QFile, 25 | Signal, 26 | Slot, 27 | ) 28 | from PySide2.QtUiTools import QUiLoader 29 | from PySide2.QtGui import ( 30 | Qt, 31 | QStandardItemModel, 32 | QStandardItem, 33 | ) 34 | 35 | from database import Database 36 | from sidebar import SidebarView, SidebarModel, Board, List 37 | from buttonTray import ButtonTray 38 | from center import CardView, CardModel, CardEditWidget 39 | 40 | 41 | class NewCardTextBox(QLineEdit): 42 | newCardRequested = Signal(str, int) 43 | getCurrentList = Signal(list) 44 | cardAdded = Signal(int) 45 | 46 | def __init__(self): 47 | QLineEdit.__init__(self) 48 | self.returnPressed.connect(self.handleReturn) 49 | self.setStyleSheet(''' 50 | QLineEdit { 51 | background-color: #2a2a2a; 52 | color: #cccccc; 53 | }; ''') 54 | return 55 | 56 | def handleReturn(self): 57 | text = self.text() 58 | listIdContainer = [] 59 | self.getCurrentList.emit(listIdContainer) 60 | listId = listIdContainer[0] 61 | 62 | self.newCardRequested.emit(text, listId) 63 | self.cardAdded.emit(listId) 64 | self.setText('') 65 | return 66 | 67 | 68 | class NewBoardButton(QPushButton): 69 | def __init__(self, parent=None): 70 | QPushButton.__init__(self, 'New Board', parent) 71 | self.setStyleSheet(''' 72 | QPushButton { 73 | font-size: 11pt; 74 | background-color: #2e2e2e; 75 | color: #cccccc; 76 | }; 77 | ''') 78 | return 79 | 80 | 81 | class MainWidget(QWidget): 82 | def __init__(self, db, parent=None): 83 | QWidget.__init__(self) 84 | self.db = db 85 | self.cardView = CardView(db) 86 | self.newCardTextBox = NewCardTextBox() 87 | 88 | mainLayout = QHBoxLayout() 89 | 90 | self.leftLayout = QVBoxLayout() 91 | self.sidebarView = SidebarView() 92 | self.leftLayout.addWidget(self.sidebarView) 93 | self.newBoardButton = NewBoardButton() 94 | self.leftLayout.addWidget(self.newBoardButton) 95 | mainLayout.addLayout(self.leftLayout) 96 | 97 | centralLayout = QVBoxLayout() 98 | centralLayout.addWidget(self.newCardTextBox) 99 | centralLayout.addWidget(self.cardView) 100 | mainLayout.addLayout(centralLayout) 101 | 102 | self.buttonTray = ButtonTray(db) 103 | mainLayout.addWidget(self.buttonTray) 104 | 105 | self.setLayout(mainLayout) 106 | 107 | self.setupSidebar() 108 | self.setupCardView() 109 | self.setupNewBoardButton() 110 | self.setupNewCardTextBox() 111 | self.setupButtonTray() 112 | return 113 | 114 | def setupNewCardTextBox(self): 115 | self.newCardTextBox.getCurrentList.connect(self.cardModel.currentList) 116 | self.newCardTextBox.newCardRequested.connect(self.makeNewCard) 117 | self.newCardTextBox.cardAdded.connect(self.cardModel.showListCards) 118 | return 119 | 120 | def setupSidebar(self): 121 | self.sidebarModel = SidebarModel(db) 122 | self.sidebarView.setModel(self.sidebarModel) 123 | self.sidebarModel.rowsInserted.connect(self.sidebarView.expandAll) 124 | self.sidebarView.renameList.connect(self.sidebarModel.onRenameList) 125 | self.sidebarView.renameBoard.connect(self.sidebarModel.onRenameBoard) 126 | self.sidebarView.deleteList.connect(self.sidebarModel.onDeleteList) 127 | self.sidebarView.deleteBoard.connect(self.sidebarModel.onDeleteBoard) 128 | self.sidebarView.addList.connect(self.sidebarModel.onAddList) 129 | self.sidebarModel.willRefresh.connect(self.sidebarView.storeExpanded) 130 | self.sidebarModel.willRefresh.connect(self.sidebarView.storeScrollValue) 131 | self.sidebarModel.refreshed.connect(self.sidebarView.restoreExpanded) 132 | self.sidebarModel.refreshed.connect(self.sidebarView.restoreScrollValue) 133 | 134 | return 135 | 136 | def setupCardView(self): 137 | self.cardModel = CardModel(self.db) 138 | self.editDialog = CardEditWidget() 139 | self.cardView.setModel(self.cardModel) 140 | self.cardModel.willUpdateCurrentList.connect(self.cardView.storeScrollValue) 141 | self.cardModel.willUpdateCurrentList.connect(self.cardView.storeSelectedIndex) 142 | self.cardModel.updatedCurrentList.connect(self.cardView.restoreScrollValue) 143 | self.cardModel.updatedCurrentList.connect(self.cardView.restoreSelectedIndex) 144 | self.sidebarView.listClicked.connect(self.cardModel.showListCards) 145 | self.sidebarModel.cardChanged.connect(self.cardModel.refresh) 146 | self.cardView.showCard.connect(self.editDialog.showCard) 147 | self.editDialog.cardEdited.connect(self.cardModel.onCardEdited) 148 | self.sidebarView.expandAll() 149 | return 150 | 151 | def setupNewBoardButton(self): 152 | self.newBoardButton.pressed.connect(self.makeNewBoard) 153 | return 154 | 155 | def setupButtonTray(self): 156 | self.buttonTray.buttonPressed.connect(self.cardModel.refresh) 157 | self.buttonTray.buttonPressed.connect(self.sidebarModel.refresh) 158 | self.buttonTray.getCurrentList.connect(self.cardModel.currentList) 159 | self.buttonTray.getSelectedCards.connect(self.cardView.selectedCards) 160 | return 161 | 162 | @Slot(str, int) 163 | def makeNewCard(self, text, listid): 164 | self.db.runCommand(f'add-card "{text}":"":-1 to {listid}') 165 | return 166 | 167 | @Slot() 168 | def makeNewBoard(self): 169 | self.db.runCommand(f'add-board "New Board"') 170 | self.sidebarModel.refresh() 171 | return 172 | 173 | 174 | class LisztWindow(QMainWindow): 175 | def __init__(self, db, parent=None): 176 | 177 | QMainWindow.__init__(self) 178 | self.setStyleSheet(''' 179 | QMainWindow { 180 | background-color: #212121; 181 | } 182 | ''') 183 | mainWidget = MainWidget(db) 184 | self.setCentralWidget(mainWidget) 185 | self.setWindowTitle('Liszt') 186 | return 187 | 188 | 189 | if __name__ == "__main__": 190 | appctxt = ApplicationContext() 191 | db = Database() 192 | mainWin = LisztWindow(db) 193 | mainWin.resize(1200, 800) 194 | mainWin.show() 195 | sys.exit(appctxt.app.exec_()) 196 | -------------------------------------------------------------------------------- /src/main/python/buttonTray.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import io 3 | 4 | from PySide2.QtWidgets import ( 5 | QApplication, 6 | QMainWindow, 7 | QLabel, 8 | QVBoxLayout, 9 | QDockWidget, 10 | QWidget, 11 | QTableView, 12 | QHBoxLayout, 13 | QTreeView, 14 | QListView, 15 | QLineEdit, 16 | QAbstractItemView, 17 | QDialog, 18 | QScrollArea, 19 | QPushButton, 20 | QStylePainter, 21 | QStyleOption, 22 | ) 23 | from PySide2.QtGui import ( 24 | Qt, 25 | QStandardItemModel, 26 | QStandardItem, 27 | QPainter, 28 | QPalette, 29 | ) 30 | from PySide2.QtCore import ( 31 | QFile, 32 | QMimeData, 33 | QByteArray, 34 | Signal, 35 | Slot, 36 | ) 37 | from PySide2 import QtCore 38 | 39 | 40 | class ActionButton(QPushButton): 41 | def __init__(self, title, parent=None): 42 | QPushButton.__init__(self, title) 43 | self.title = title 44 | self.setStyleSheet(''' 45 | QPushButton { 46 | font-size: 11pt; 47 | background-color: #2e2e2e; 48 | color: #cccccc; 49 | max-width: 145px; 50 | min-width: 145px; 51 | }; 52 | ''') 53 | return 54 | 55 | 56 | class EditButton(QPushButton): 57 | def __init__(self): 58 | QPushButton.__init__(self, 'Edit') 59 | self.setStyleSheet(''' 60 | QPushButton { 61 | font-size: 10pt; 62 | background-color: #2e2e2e; 63 | color: #cccccc; 64 | max-width: 30px; 65 | }; 66 | ''') 67 | return 68 | 69 | 70 | class DeleteButton(QPushButton): 71 | def __init__(self): 72 | QPushButton.__init__(self, 'Del') 73 | self.setStyleSheet(''' 74 | QPushButton { 75 | font-size: 10pt; 76 | background-color: #2e2e2e; 77 | color: #cccccc; 78 | max-width: 30px; 79 | }; 80 | ''') 81 | return 82 | 83 | 84 | class EditDialog(QDialog): 85 | buttonEditsSaved = Signal(str, str, int) 86 | 87 | def __init__(self): 88 | QDialog.__init__(self) 89 | self.buttonId = -1 90 | self.setStyleSheet(''' 91 | QDialog { 92 | background-color: #2e2e2e; 93 | color: #cccccc; 94 | min-width: 500px; 95 | }; 96 | ''') 97 | 98 | self.layout = QVBoxLayout() 99 | self.setLayout(self.layout) 100 | 101 | nameLayout = QHBoxLayout() 102 | 103 | nameLabel = QLabel('Name:') 104 | nameLabel.setStyleSheet('QLabel { color: #cccccc; };') 105 | nameLayout.addWidget(nameLabel) 106 | 107 | self.nameTextEdit = QLineEdit() 108 | self.nameTextEdit.setStyleSheet(''' 109 | QLineEdit { 110 | background-color: #2a2a2a; 111 | color: #cccccc; 112 | }; ''') 113 | nameLayout.addWidget(self.nameTextEdit) 114 | self.layout.addLayout(nameLayout) 115 | 116 | commandLayout = QHBoxLayout() 117 | 118 | commandLabel = QLabel('Command:') 119 | commandLabel.setStyleSheet('QLabel { color: #cccccc; };') 120 | commandLayout.addWidget(commandLabel) 121 | 122 | self.commandTextEdit = QLineEdit() 123 | self.commandTextEdit.setStyleSheet(''' 124 | QLineEdit { 125 | background-color: #2a2a2a; 126 | color: #cccccc; 127 | }; ''') 128 | commandLayout.addWidget(self.commandTextEdit) 129 | self.layout.addLayout(commandLayout) 130 | 131 | buttonLayout = QHBoxLayout() 132 | cancelButton = QPushButton('Cancel') 133 | cancelButton.setStyleSheet(''' 134 | QPushButton { 135 | background-color: #2e2e2e; 136 | color: #cccccc; 137 | }; 138 | ''') 139 | cancelButton.clicked.connect(self.close) 140 | 141 | saveButton = QPushButton('Save') 142 | saveButton.setStyleSheet(''' 143 | QPushButton { 144 | background-color: #2e2e2e; 145 | color: #cccccc; 146 | }; 147 | ''') 148 | saveButton.clicked.connect(self.handleSave) 149 | 150 | buttonLayout.addWidget(saveButton) 151 | buttonLayout.addWidget(cancelButton) 152 | self.layout.addLayout(buttonLayout) 153 | return 154 | 155 | @Slot() 156 | @Slot(str, str, int) 157 | def showWithText(self, name='', cmd='', buttonId=-1): 158 | self.buttonId = buttonId 159 | self.commandTextEdit.setText(cmd) 160 | self.nameTextEdit.setText(name) 161 | self.show() 162 | return 163 | 164 | @Slot() 165 | def handleSave(self): 166 | cmdText = self.commandTextEdit.text() 167 | nameText = self.nameTextEdit.text() 168 | self.buttonEditsSaved.emit(nameText, cmdText, self.buttonId) 169 | self.close() 170 | return 171 | 172 | 173 | class ButtonRow(QWidget): 174 | dispatchAction = Signal(int) 175 | delButtonPressed = Signal(int) 176 | editButtonPressed = Signal(str, str, int) 177 | 178 | def __init__(self, title, buttonId, command, parent=None): 179 | QWidget.__init__(self) 180 | self.layout = QHBoxLayout() 181 | self.actionButton = ActionButton(title) 182 | self.actionButton.pressed.connect(self.handleActionButton) 183 | self.editButton = EditButton() 184 | self.editButton.pressed.connect(self.sendEditInfo) 185 | self.delButton = DeleteButton() 186 | self.delButton.pressed.connect(self.handleDeleteButton) 187 | 188 | self.buttonTitle = title 189 | self.command = command 190 | self.buttonId = buttonId 191 | 192 | self.setStyleSheet(''' 193 | QWidget { 194 | background-color: #2e2e2e; 195 | }; 196 | ''') 197 | 198 | self.layout.addWidget(self.actionButton) 199 | self.layout.addWidget(self.editButton) 200 | self.layout.addWidget(self.delButton) 201 | self.setLayout(self.layout) 202 | self.layout.setContentsMargins(0, 0, 0, 0) 203 | 204 | self.setAttribute(QtCore.Qt.WA_StyledBackground, True) 205 | return 206 | 207 | @Slot() 208 | def handleDeleteButton(self): 209 | self.delButtonPressed.emit(self.buttonId) 210 | 211 | @Slot() 212 | def sendEditInfo(self): 213 | self.editButtonPressed.emit(self.buttonTitle, self.command, self.buttonId) 214 | return 215 | 216 | @Slot() 217 | def handleActionButton(self): 218 | self.dispatchAction.emit(self.buttonId) 219 | return 220 | 221 | 222 | class TrayContent(QWidget): 223 | def __init__(self): 224 | QWidget.__init__(self) 225 | self.setStyleSheet(''' 226 | QWidget { 227 | background-color: #2e2e2e; 228 | color: #cccccc; 229 | }; 230 | ''') 231 | return 232 | 233 | 234 | class ButtonTray(QScrollArea): 235 | getSelectedCards = Signal(list) 236 | getCurrentList = Signal(list) 237 | buttonPressed = Signal() 238 | 239 | def __init__(self, db, parent=None): 240 | QScrollArea.__init__(self) 241 | self.db = db 242 | self.setStyleSheet(''' 243 | QScrollArea { 244 | background-color: #2e2e2e; 245 | color: #cccccc; 246 | min-width: 250px; 247 | max-width: 250px 248 | }; 249 | ''') 250 | self.verticalScrollBar().setStyleSheet(''' 251 | QScrollBar:vertical { 252 | background: #2e2e2e; 253 | }; 254 | ''') 255 | 256 | self.editDialog = EditDialog() 257 | self.editDialog.buttonEditsSaved.connect(self.handleEditChanges) 258 | 259 | self.showButtons() 260 | self.buttons = [] 261 | 262 | self.buttonPressed.connect(self.showButtons) 263 | return 264 | 265 | @Slot() 266 | def showButtons(self): 267 | self.content = TrayContent() 268 | layout = QVBoxLayout() 269 | result = self.db.runCommand('show-buttons') 270 | self.buttonRows = [] 271 | contentHeight = 0 272 | buttonHeight = 50 273 | with io.StringIO(result) as f: 274 | reader = csv.DictReader(f, delimiter='\t') 275 | for row in reader: 276 | buttonName = row['name'] 277 | buttonId = int(row['id']) 278 | buttonCmd = self.db.runCommand(f'get-button {buttonId}') 279 | 280 | buttonRow = ButtonRow(buttonName, buttonId, buttonCmd) 281 | buttonRow.dispatchAction.connect(self.handleActionButton) 282 | buttonRow.editButtonPressed.connect( 283 | self.editDialog.showWithText) 284 | buttonRow.delButtonPressed.connect(self.handleDeleteButton) 285 | 286 | self.buttonRows.append(buttonRow) 287 | layout.addWidget(buttonRow) 288 | contentHeight += buttonHeight 289 | 290 | self.additionButton = QPushButton('New Button') 291 | self.additionButton.pressed.connect(self.handleAdditionButton) 292 | layout.addWidget(self.additionButton) 293 | contentHeight += buttonHeight 294 | 295 | self.content.setLayout(layout) 296 | self.content.setMinimumSize(220, contentHeight) 297 | self.content.setAttribute(QtCore.Qt.WA_StyledBackground, True) 298 | self.setWidget(self.content) 299 | return 300 | 301 | @Slot(int) 302 | def handleDeleteButton(self, buttonId): 303 | cmd = f'delete-button {buttonId}' 304 | self.db.runCommand(cmd) 305 | self.showButtons() 306 | return 307 | 308 | 309 | @Slot() 310 | def handleAdditionButton(self): 311 | self.editDialog.showWithText() 312 | return 313 | 314 | @Slot(int) 315 | def handleActionButton(self, buttonId): 316 | buttonCmd = self.db.runCommand(f'get-button {buttonId}') 317 | selectedCards = [] 318 | currentList = [] 319 | 320 | self.getSelectedCards.emit(selectedCards) 321 | self.getCurrentList.emit(currentList) 322 | 323 | if '$CARD' in buttonCmd: 324 | for card in selectedCards: 325 | newCmd = str(buttonCmd) 326 | newCmd = newCmd.replace('$CARD', str(card)) 327 | newCmd = newCmd.replace('$LIST', str(currentList[0])) 328 | self.db.runCommand(newCmd) 329 | else: 330 | newCmd = str(buttonCmd) 331 | newCmd.replace('$LIST', str(currentList[0])) 332 | self.db.runCommand(newCmd) 333 | self.buttonPressed.emit() 334 | return 335 | 336 | @Slot(str, str, int) 337 | def handleEditChanges(self, name, command, buttonId): 338 | if buttonId != -1: 339 | command = f'rename-button {buttonId} "{name}" "{command}"' 340 | else: 341 | command = f'add-button "{name}" "{command}"' 342 | self.db.runCommand(command) 343 | self.showButtons() 344 | return 345 | 346 | -------------------------------------------------------------------------------- /src/main/python/center.py: -------------------------------------------------------------------------------- 1 | import io 2 | import csv 3 | import datetime 4 | 5 | from PySide2.QtWidgets import ( 6 | QApplication, 7 | QMainWindow, 8 | QLabel, 9 | QVBoxLayout, 10 | QDockWidget, 11 | QWidget, 12 | QTableView, 13 | QHBoxLayout, 14 | QTreeView, 15 | QListView, 16 | QLineEdit, 17 | QAbstractItemView, 18 | QDialog, 19 | QTextEdit, 20 | QPushButton, 21 | QCalendarWidget, 22 | ) 23 | from PySide2.QtGui import ( 24 | Qt, 25 | QStandardItemModel, 26 | QStandardItem, 27 | ) 28 | from PySide2.QtCore import ( 29 | QFile, 30 | QMimeData, 31 | QByteArray, 32 | QModelIndex, 33 | QDate, 34 | Qt, 35 | Signal, 36 | Slot, 37 | ) 38 | 39 | from database import decodeFromDB, encodeForDB 40 | 41 | 42 | def getCards(db, listId): 43 | if listId == -1: 44 | return [] 45 | result = db.runCommand(f'show-cards {listId}') 46 | cards = [] 47 | with io.StringIO(result) as f: 48 | reader = csv.DictReader(f, delimiter='\t') 49 | for idx, row in enumerate(reader): 50 | card = Card( 51 | row['title'], 52 | int(row['id']), 53 | idx, 54 | row['content'], 55 | int(row['due'])) 56 | cards.append(card) 57 | return cards 58 | 59 | 60 | def toLocalTime(sec): 61 | # Seconds since epoch to local time 62 | dateInfo = datetime.datetime.fromtimestamp(sec) 63 | result = dateInfo.strftime('%A, %d %b %Y') 64 | return result 65 | 66 | # TODO: Create a json serialization of Card, List, and Board 67 | 68 | 69 | class Card(QStandardItem): 70 | def __init__(self, name, rowid, idx, content, dueDate): 71 | QStandardItem.__init__(self) 72 | self.itemType = 'CARD' 73 | self.name = decodeFromDB(name) 74 | self.content = decodeFromDB(content) 75 | self.dueDate = int(dueDate) 76 | self.rowid = int(rowid) 77 | suffix = '' 78 | if self.content: 79 | suffix += ' *' 80 | if self.dueDate > 0: 81 | dateInfo = datetime.datetime.fromtimestamp(dueDate) 82 | suffix += f" (Due: {dateInfo.strftime('%A, %d %b %Y')})" 83 | self.setText(self.name + suffix) 84 | self.idx = int(idx) 85 | 86 | def __str__(self): 87 | return f'{self.itemType}::{self.rowid}::{self.idx}::{self.name}' 88 | 89 | 90 | class CardView(QListView): 91 | showCard = Signal(Card) 92 | 93 | def __init__(self, db, parent=None): 94 | QListView.__init__(self) 95 | self.db = db 96 | self.setStyleSheet(''' 97 | QListView { 98 | font-size: 16pt; 99 | background-color: #2e2e2e; 100 | color: #cccccc; 101 | } 102 | 103 | QListView::item { 104 | padding: 10px; 105 | } 106 | ''') 107 | self.setWordWrap(True) 108 | self.setDragDropMode(QAbstractItemView.DragDrop) 109 | self.doubleClicked.connect(self.onDoubleClick) 110 | self.scrollValue = 0 111 | return 112 | 113 | @Slot(QModelIndex) 114 | def onDoubleClick(self, index): 115 | card = self.model().itemFromIndex(index) 116 | self.showCard.emit(card) 117 | return 118 | 119 | @Slot(list) 120 | def selectedCards(self, cardList): 121 | indexes = self.selectedIndexes() 122 | for idx in indexes: 123 | cardModel = self.model().itemFromIndex(idx) 124 | cardId = cardModel.rowid 125 | cardList.append(cardId) 126 | return 127 | 128 | 129 | @Slot() 130 | def storeSelectedIndex(self): 131 | value = self.selectedIndexes()[0].row() 132 | self.selectedIndex = value 133 | 134 | @Slot() 135 | def restoreSelectedIndex(self): 136 | model = self.model() 137 | maxIdx = model.rowCount() - 1 138 | if maxIdx == -1: 139 | return 140 | newIdx = min(self.selectedIndex, maxIdx) 141 | rowIdx = model.index(newIdx, 0) 142 | self.setCurrentIndex(rowIdx) 143 | 144 | @Slot() 145 | def storeScrollValue(self): 146 | value = self.verticalScrollBar().value() 147 | self.scrollValue = value 148 | 149 | @Slot() 150 | def restoreScrollValue(self): 151 | self.verticalScrollBar().setValue(self.scrollValue) 152 | 153 | 154 | class CardModel(QStandardItemModel): 155 | willUpdateCurrentList = Signal() 156 | updatedCurrentList = Signal() 157 | 158 | def __init__(self, db): 159 | QStandardItemModel.__init__(self, parent=None) 160 | self.db = db 161 | self.listId = -1 162 | self.changedList = False 163 | return 164 | 165 | @Slot() 166 | def refresh(self): 167 | if not self.changedList: 168 | self.willUpdateCurrentList.emit() 169 | self.clear() 170 | try: 171 | for card in reversed(getCards(self.db, self.listId)): 172 | self.appendRow(card) 173 | except TypeError: 174 | pass 175 | if not self.changedList: 176 | self.updatedCurrentList.emit() 177 | self.changedList = False 178 | return 179 | 180 | @Slot(int) 181 | def showListCards(self, listId): 182 | self.changedList = True 183 | self.listId = listId 184 | self.refresh() 185 | return 186 | 187 | @Slot(list) 188 | def currentList(self, listidContainer): 189 | listidContainer.append(self.listId) 190 | return 191 | 192 | def dropMimeData(self, data, action, row, column, parent): 193 | result = False 194 | if 'CARD' in data.text(): 195 | _, cardId, cardIdx, _ = data.text().split('::') 196 | cardId, cardIdx = int(cardId), int(cardIdx) 197 | row = self.rowCount() - row 198 | 199 | if row == cardIdx or (row - 1) == cardIdx: 200 | return True 201 | 202 | if cardIdx > row: 203 | newIdx = row 204 | else: 205 | newIdx = row - 1 206 | 207 | cmd = f'shift-card {cardId} to {newIdx}' 208 | self.db.runCommand(cmd) 209 | self.refresh() 210 | result = True 211 | return result 212 | 213 | def canDropMimeData(self, data, action, row, col, parent): 214 | isCard = 'CARD' in data.text() 215 | isBetweenCards = (row != -1 and self.itemFromIndex(parent) is None) 216 | return (isCard and isBetweenCards) 217 | 218 | def mimeData(self, indexes): 219 | result = QMimeData() 220 | item = self.itemFromIndex(indexes[0]) 221 | result.setText(str(item)) 222 | return result 223 | 224 | def mimeTypes(self): 225 | return ['text/plain'] 226 | 227 | @Slot() 228 | def onCardEdited(self, title, content, dueDate, cardId): 229 | title = encodeForDB(title) 230 | content = encodeForDB(content) 231 | self.db.runCommand(f'rename-card {cardId} "{title}"') 232 | self.db.runCommand(f'set-card-content {cardId} "{content}"') 233 | self.db.runCommand(f'set-due-date {cardId} {dueDate}') 234 | self.refresh() 235 | return 236 | 237 | 238 | class CardEditWidget(QDialog): 239 | cardEdited = Signal(str, str, int, int) # (name, content, dueDate, id) 240 | 241 | def __init__(self): 242 | QDialog.__init__(self) 243 | self.setStyleSheet(''' 244 | QDialog { 245 | background-color: #2e2e2e; 246 | color: #cccccc; 247 | min-width: 500px; 248 | }; 249 | ''') 250 | 251 | self.cardTitle = '' 252 | self.dueDate = -1 253 | self.content = '' 254 | self.cardId = -1 255 | 256 | self.layout = QVBoxLayout() 257 | self.setLayout(self.layout) 258 | 259 | nameLayout = self.makeNameLayout() 260 | self.layout.addLayout(nameLayout) 261 | 262 | dueDateLayout = self.makeDueDateLayout() 263 | self.layout.addLayout(dueDateLayout) 264 | 265 | contentLayout = self.makeContentLayout() 266 | self.layout.addLayout(contentLayout) 267 | 268 | buttonLayout = self.makeButtonLayout() 269 | self.layout.addLayout(buttonLayout) 270 | return 271 | 272 | def makeNameLayout(self): 273 | nameLayout = QHBoxLayout() 274 | 275 | nameLabel = QLabel('Title:') 276 | nameLabel.setStyleSheet('QLabel { color: #cccccc; };') 277 | nameLayout.addWidget(nameLabel) 278 | 279 | self.nameTextEdit = QLineEdit() 280 | self.nameTextEdit.setStyleSheet(''' 281 | QLineEdit { 282 | background-color: #2a2a2a; 283 | color: #cccccc; 284 | }; ''') 285 | nameLayout.addWidget(self.nameTextEdit) 286 | return nameLayout 287 | 288 | def makeDueDateLayout(self): 289 | dueDateLayout = QVBoxLayout() 290 | rowLayout = QHBoxLayout() 291 | dateLabel = QLabel('Due Date:') 292 | dateLabel.setStyleSheet('QLabel { color: #cccccc; };') 293 | rowLayout.addWidget(dateLabel) 294 | dateLineEdit = QLineEdit() 295 | dateLineEdit.setStyleSheet(''' 296 | QLineEdit { 297 | background-color: #2a2a2a; 298 | color: #cccccc; 299 | }; ''') 300 | if self.dueDate > 0: 301 | dateLineEdit.setText(toLocalTime(self.dueDate)) 302 | else: 303 | dateLineEdit.setText('None') 304 | self.dateLineEdit = dateLineEdit 305 | 306 | calWidget = QCalendarWidget() 307 | calWidget.setStyleSheet(''' 308 | QCalendarWidget QWidget { 309 | background-color: #2a2a2a; 310 | alternate-background-color: #303030; 311 | color: #cccccc; 312 | } 313 | QCalendarWidget QToolButton { 314 | background-color: #2a2a2a; 315 | alternate-background-color: #303030; 316 | color: #cccccc; 317 | } 318 | QCalendarWidget QAbstractItemView { 319 | background-color: #2a2a2a; 320 | alternate-background-color: #303030; 321 | color: #cccccc; 322 | } ''') 323 | calWidget.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader) 324 | calWidget.clicked.connect(self.onCalendarClick) 325 | 326 | rowLayout.addWidget(dateLineEdit) 327 | dueDateLayout.addLayout(rowLayout) 328 | dueDateLayout.addWidget(calWidget) 329 | return dueDateLayout 330 | 331 | def makeContentLayout(self): 332 | contentLayout = QVBoxLayout() 333 | contentLabel = QLabel('Content:') 334 | contentLabel.setStyleSheet('QLabel { color: #cccccc; };') 335 | contentLayout.addWidget(contentLabel) 336 | 337 | self.contentEdit = QTextEdit() 338 | self.contentEdit.setStyleSheet(''' 339 | QTextEdit { 340 | background-color: #2a2a2a; 341 | color: #cccccc; 342 | }; ''') 343 | contentLayout.addWidget(self.contentEdit) 344 | return contentLayout 345 | 346 | def makeButtonLayout(self): 347 | buttonLayout = QHBoxLayout() 348 | cancelButton = QPushButton('Cancel') 349 | cancelButton.setStyleSheet(''' 350 | QPushButton { 351 | background-color: #2e2e2e; 352 | color: #cccccc; 353 | }; 354 | ''') 355 | cancelButton.clicked.connect(self.close) 356 | 357 | saveButton = QPushButton('Save') 358 | saveButton.setStyleSheet(''' 359 | QPushButton { 360 | background-color: #2e2e2e; 361 | color: #cccccc; 362 | }; 363 | ''') 364 | saveButton.clicked.connect(self.handleSave) 365 | 366 | buttonLayout.addWidget(saveButton) 367 | buttonLayout.addWidget(cancelButton) 368 | return buttonLayout 369 | 370 | @Slot(Card) 371 | def showCard(self, card): 372 | self.cardTitle = card.name 373 | self.nameTextEdit.setText(card.name) 374 | self.dueDate = card.dueDate 375 | if self.dueDate > 0: 376 | self.dateLineEdit.setText(toLocalTime(self.dueDate)) 377 | else: 378 | self.dateLineEdit.setText('None') 379 | self.content = card.content 380 | self.contentEdit.setPlainText(card.content) 381 | self.cardId = card.rowid 382 | self.show() 383 | return 384 | 385 | @Slot() 386 | def handleSave(self): 387 | self.close() 388 | self.content = self.contentEdit.toPlainText() 389 | self.cardTitle = self.nameTextEdit.text() 390 | self.cardEdited.emit( 391 | self.cardTitle, self.content, 392 | self.dueDate, self.cardId) 393 | return 394 | 395 | @Slot(QDate) 396 | def onCalendarClick(self, date): 397 | dateInfo = date.startOfDay(Qt.TimeSpec.LocalTime) 398 | self.dueDate = dateInfo.toSecsSinceEpoch() 399 | self.dateLineEdit.setText(toLocalTime(self.dueDate)) 400 | -------------------------------------------------------------------------------- /src/main/python/sidebar.py: -------------------------------------------------------------------------------- 1 | import io 2 | import csv 3 | from PySide2.QtWidgets import ( 4 | QApplication, 5 | QMainWindow, 6 | QLabel, 7 | QDockWidget, 8 | QWidget, 9 | QTableView, 10 | QHBoxLayout, 11 | QVBoxLayout, 12 | QTreeView, 13 | QListView, 14 | QLineEdit, 15 | QAbstractItemView, 16 | QMenu, 17 | QInputDialog, 18 | ) 19 | from PySide2.QtGui import ( 20 | Qt, 21 | QStandardItemModel, 22 | QStandardItem, 23 | QCursor, 24 | ) 25 | from PySide2.QtCore import ( 26 | QFile, 27 | QPoint, 28 | QMimeData, 29 | Signal, 30 | Slot, 31 | ) 32 | from database import encodeForDB, decodeFromDB 33 | 34 | 35 | def getBoards(db): 36 | result = db.runCommand('show-boards') 37 | boards = [] 38 | with io.StringIO(result) as f: 39 | reader = csv.DictReader(f, delimiter='\t') 40 | for idx, row in enumerate(reader): 41 | board = Board(row['title'], row['id'], idx) 42 | boards.append(board) 43 | return boards 44 | 45 | 46 | def getLists(db, boardId): 47 | if boardId == -1: 48 | return [] 49 | result = db.runCommand(f'show-lists {boardId}') 50 | lists = [] 51 | with io.StringIO(result) as f: 52 | reader = csv.DictReader(f, delimiter='\t') 53 | for idx, row in enumerate(reader): 54 | _list = List(decodeFromDB(row['title']), row['id'], idx) 55 | lists.append(_list) 56 | return lists 57 | 58 | 59 | class Board(QStandardItem): 60 | def __init__(self, name, rowid, idx): 61 | QStandardItem.__init__(self) 62 | self.itemType = 'BOARD' 63 | self.name = decodeFromDB(name) 64 | self.rowid = int(rowid) 65 | self.setText(f'#{rowid} {name}') 66 | self.idx = int(idx) 67 | 68 | def __str__(self): 69 | return f'{self.itemType}::{self.rowid}::{self.idx}::{self.name}' 70 | 71 | def __hash__(self): 72 | return self.rowid 73 | 74 | 75 | class List(QStandardItem): 76 | def __init__(self, name, rowid, idx): 77 | QStandardItem.__init__(self) 78 | self.itemType = 'LIST' 79 | self.name = decodeFromDB(name) 80 | self.rowid = int(rowid) 81 | self.setText(f'#{rowid} {name}') 82 | self.idx = int(idx) 83 | 84 | def __str__(self): 85 | return f'{self.itemType}::{self.rowid}::{self.idx}::{self.name}' 86 | 87 | 88 | class BoardContextMenu(QMenu): 89 | renameBoardClick = Signal() 90 | deleteBoardClick = Signal() 91 | addListToBoardClick = Signal() 92 | 93 | def __init__(self, parent=None): 94 | QMenu.__init__(self) 95 | action = self.addAction('Rename') 96 | action.triggered.connect(lambda x: self.renameBoardClick.emit()) 97 | 98 | action = self.addAction('Delete') 99 | action.triggered.connect(lambda x: self.deleteBoardClick.emit()) 100 | 101 | action = self.addAction('Add List') 102 | action.triggered.connect(lambda x: self.addListToBoardClick.emit()) 103 | 104 | self.setStyleSheet(''' 105 | QMenu { 106 | background-color: #2e2e2e; 107 | color: #cccccc; 108 | }; 109 | ''') 110 | 111 | 112 | class ListContextMenu(QMenu): 113 | renameListClick = Signal() 114 | deleteListClick = Signal() 115 | 116 | def __init__(self, parent=None): 117 | QMenu.__init__(self) 118 | action = self.addAction('Rename') 119 | action.triggered.connect(lambda x: self.renameListClick.emit()) 120 | 121 | action = self.addAction('Delete') 122 | action.triggered.connect(lambda x: self.deleteListClick.emit()) 123 | 124 | self.setStyleSheet(''' 125 | QMenu { 126 | background-color: #2e2e2e; 127 | color: #cccccc; 128 | }; 129 | ''') 130 | 131 | 132 | class RenameDeleteDialog(QInputDialog): 133 | def __init__(self, parent=None): 134 | QInputDialog.__init__(self, parent=parent) 135 | self.setStyleSheet(''' 136 | QInputDialog { 137 | background-color: #2e2e2e; 138 | color: #cccccc; 139 | }; 140 | ''') 141 | return 142 | 143 | def showWithSuggestion(self, suggestion): 144 | self.setTextValue(suggestion) 145 | return 146 | 147 | 148 | class SidebarView(QTreeView): 149 | listClicked = Signal(int) 150 | readyForUpdate = Signal() 151 | renameList = Signal(str, int) 152 | renameBoard = Signal(str, int) 153 | deleteList = Signal(int) 154 | deleteBoard = Signal(int) 155 | addList = Signal(str, int) 156 | 157 | def __init__(self, parent=None): 158 | QTreeView.__init__(self, parent=parent) 159 | 160 | self.setStyleSheet(''' 161 | QTreeView { 162 | font-size: 14pt; 163 | background-color: #2e2e2e; 164 | color: #cccccc; 165 | min-width: 125px; 166 | max-width: 250px 167 | } 168 | 169 | QTreeView::item { 170 | padding: 5px; 171 | } 172 | ''') 173 | 174 | self.header().hide() 175 | self.clicked.connect(self.sendListId) 176 | self.setDragDropMode(QAbstractItemView.DragDrop) 177 | self.setWordWrap(True) 178 | 179 | self.inputDialog = RenameDeleteDialog() 180 | self.setEditTriggers(QAbstractItemView.NoEditTriggers) 181 | 182 | self.setupContextMenus() 183 | return 184 | 185 | def setupContextMenus(self): 186 | self.boardMenu = BoardContextMenu() 187 | self.boardMenu.renameBoardClick.connect(self.onRenameBoardClick) 188 | self.boardMenu.deleteBoardClick.connect(self.onDeleteBoardClick) 189 | self.boardMenu.addListToBoardClick.connect(self.onAddListToBoardClick) 190 | 191 | self.listMenu = ListContextMenu() 192 | self.listMenu.renameListClick.connect(self.onRenameListClick) 193 | self.listMenu.deleteListClick.connect(self.onDeleteListClick) 194 | 195 | self.setContextMenuPolicy(Qt.CustomContextMenu) 196 | self.customContextMenuRequested.connect( 197 | self.onCustomContextMenuRequested) 198 | return 199 | 200 | def sendListId(self, modelIdx): 201 | item = modelIdx.model().itemFromIndex(modelIdx) 202 | if type(item) == List: 203 | listid = int(item.rowid) 204 | self.listClicked.emit(listid) 205 | return 206 | 207 | @Slot() 208 | def onRenameListClick(self): 209 | listIndex = self.selectedIndexes()[0] 210 | item = listIndex.model().itemFromIndex(listIndex) 211 | titleText = "Rename List" 212 | labelText = "New Name:" 213 | newName, ok = self.inputDialog.getText(self, titleText, labelText) 214 | if ok: 215 | self.renameList.emit(newName, int(item.rowid)) 216 | return 217 | 218 | @Slot() 219 | def onDeleteListClick(self): 220 | listIndex = self.selectedIndexes()[0] 221 | item = listIndex.model().itemFromIndex(listIndex) 222 | titleText = "Delete List" 223 | labelText = f'To delete, type "{item.name}"' 224 | confirm, ok = self.inputDialog.getText(self, titleText, labelText) 225 | if ok and confirm == item.name: 226 | self.deleteList.emit(item.rowid) 227 | return 228 | 229 | @Slot() 230 | def onRenameBoardClick(self): 231 | boardIndex = self.selectedIndexes()[0] 232 | item = boardIndex.model().itemFromIndex(boardIndex) 233 | titleText = "Rename Board" 234 | labelText = "New Name:" 235 | newName, ok = self.inputDialog.getText(self, titleText, labelText) 236 | if ok: 237 | self.renameBoard.emit(newName, item.rowid) 238 | return 239 | 240 | @Slot() 241 | def onDeleteBoardClick(self): 242 | boardIndex = self.selectedIndexes()[0] 243 | item = boardIndex.model().itemFromIndex(boardIndex) 244 | titleText = "Delete Board" 245 | labelText = f'To delete, type "{item.name}"' 246 | confirm, ok = self.inputDialog.getText(self, titleText, labelText) 247 | if ok and confirm == item.name: 248 | self.deleteBoard.emit(item.rowid) 249 | return 250 | 251 | @Slot() 252 | def onAddListToBoardClick(self): 253 | boardIndex = self.selectedIndexes()[0] 254 | item = boardIndex.model().itemFromIndex(boardIndex) 255 | titleText = "New List" 256 | labelText = "Name:" 257 | newName, ok = self.inputDialog.getText(self, titleText, labelText) 258 | if ok: 259 | self.addList.emit(newName, item.rowid) 260 | return 261 | 262 | @Slot(QPoint) 263 | def onCustomContextMenuRequested(self, point): 264 | index = self.indexAt(point) 265 | item = self.model().itemFromIndex(index) 266 | globalPoint = self.viewport().mapToGlobal(point) 267 | if type(item) == Board: 268 | self.boardMenu.exec_(globalPoint) 269 | elif type(item) == List: 270 | self.listMenu.exec_(globalPoint) 271 | self.listClicked.emit(int(item.rowid)) 272 | return 273 | 274 | @Slot() 275 | def storeExpanded(self): 276 | self.expanded = {} 277 | model = self.model() 278 | for i in range(model.rowCount()): 279 | rowIdx = model.index(i, 0) 280 | item = model.item(i, 0) 281 | self.expanded[item.rowid] = self.isExpanded(rowIdx) 282 | 283 | @Slot() 284 | def restoreExpanded(self): 285 | model = self.model() 286 | for i in range(model.rowCount()): 287 | rowIdx = model.index(i, 0) 288 | item = model.item(i, 0) 289 | self.setExpanded(rowIdx, self.expanded[item.rowid]) 290 | 291 | @Slot() 292 | def storeScrollValue(self): 293 | value = self.verticalScrollBar().value() 294 | self.scrollValue = value 295 | 296 | @Slot() 297 | def restoreScrollValue(self): 298 | self.verticalScrollBar().setValue(self.scrollValue) 299 | 300 | class SidebarModel(QStandardItemModel): 301 | cardChanged = Signal() 302 | willRefresh = Signal() 303 | refreshed = Signal() 304 | 305 | def __init__(self, db): 306 | QStandardItemModel.__init__(self, parent=None) 307 | self.db = db 308 | self.refresh() 309 | return 310 | 311 | def refresh(self): 312 | self.willRefresh.emit() 313 | self.clear() 314 | rootNode = self.invisibleRootItem() 315 | for board in getBoards(self.db): 316 | rootNode.appendRow(board) 317 | for _list in getLists(self.db, board.rowid): 318 | board.appendRow(_list) 319 | self.refreshed.emit() 320 | return 321 | 322 | def dropMimeData(self, data, action, row, column, parent): 323 | target = self.itemFromIndex(parent) 324 | result = False 325 | if type(target) == List and 'CARD' in data.text(): 326 | # A card being dropped on a list 327 | cardId = data.text().split('::')[1] 328 | cmd = f'move-card {cardId} to {target.rowid}' 329 | self.db.runCommand(cmd) 330 | self.cardChanged.emit() 331 | result = True 332 | 333 | elif type(target) == Board and 'LIST' in data.text(): 334 | # A list being dropped in between lists 335 | # TODO: Take care of case where you drop from one board to another 336 | _, listId, listIdx, _ = data.text().split('::') 337 | listId, listIdx = int(listId), int(listIdx) 338 | 339 | if row == listIdx or (row - 1) == listIdx: 340 | return True 341 | 342 | if listIdx > row: 343 | newIdx = row 344 | else: 345 | newIdx = row - 1 346 | 347 | cmd = f'shift-list {listId} to {newIdx}' 348 | self.db.runCommand(cmd) 349 | self.refresh() 350 | result = True 351 | 352 | elif target is None and 'BOARD' in data.text(): 353 | # A board being dropped between boards 354 | result = True 355 | 356 | return result 357 | 358 | def canDropMimeData(self, data, action, row, col, parent): 359 | target = self.itemFromIndex(parent) 360 | isCard = 'CARD' in data.text() 361 | isBetweenCards = (type(target) == List and col == -1) 362 | 363 | isList = 'LIST' in data.text() 364 | isBetweenLists = (type(target) == Board and col == 0) 365 | 366 | isBoard = 'BOARD' in data.text() 367 | isBetweenBoards = (target is None and col == 0) 368 | 369 | valid = (isCard and isBetweenCards) 370 | valid = valid or (isList and isBetweenLists) 371 | valid = valid or (isBoard and isBetweenBoards) 372 | return valid 373 | 374 | def mimeTypes(self): 375 | return ['text/plain'] 376 | 377 | @Slot(str, int) 378 | def onRenameList(self, name, rowid): 379 | cmd = f'rename-list {rowid} "{name}"' 380 | self.db.runCommand(cmd) 381 | self.refresh() 382 | return 383 | 384 | @Slot(str, int) 385 | def onRenameBoard(self, name, rowid): 386 | cmd = f'rename-board {rowid} "{name}"' 387 | self.db.runCommand(cmd) 388 | self.refresh() 389 | return 390 | 391 | @Slot(int) 392 | def onDeleteList(self, rowid): 393 | cmd = f'delete-list {rowid}' 394 | self.db.runCommand(cmd) 395 | self.refresh() 396 | return 397 | 398 | @Slot(int) 399 | def onDeleteBoard(self, rowid): 400 | cmd = f'delete-board {rowid}' 401 | self.db.runCommand(cmd) 402 | self.refresh() 403 | return 404 | 405 | @Slot(str, int) 406 | def onAddList(self, name, boardid): 407 | cmd = f'add-list "{name}" to {boardid}' 408 | self.db.runCommand(cmd) 409 | self.refresh() 410 | return 411 | 412 | def mimeData(self, indexes): 413 | result = QMimeData() 414 | item = self.itemFromIndex(indexes[0]) 415 | result.setText(str(item)) 416 | return result 417 | -------------------------------------------------------------------------------- /src/main/python/database.py: -------------------------------------------------------------------------------- 1 | import json 2 | import re 3 | import sqlite3 4 | import os 5 | import time 6 | # TODO: Add support for letter hash ids 7 | 8 | S_QUOTE = "'" 9 | D_QUOTE = '"' 10 | 11 | 12 | def encodeForDB(content): 13 | content = content.replace('\t', ' '*4) 14 | content = content.replace('\n', '<|NEWLINE|>') 15 | content = content.replace(S_QUOTE, S_QUOTE*2) 16 | return content 17 | 18 | 19 | def decodeFromDB(content): 20 | content = content.replace('<|NEWLINE|>', '\n') 21 | content = content.replace(S_QUOTE*2, S_QUOTE) 22 | return content 23 | 24 | 25 | class Database: 26 | def __init__(self, filename='data.db'): 27 | self.filename = filename 28 | if not os.path.exists(filename): 29 | self.db = sqlite3.connect(self.filename) 30 | self.initializeDb() 31 | else: 32 | self.db = sqlite3.connect(self.filename) 33 | 34 | self.boardIdx = 0 35 | 36 | self.actions = { 37 | 'where': self.where, 38 | 'goto': self.goto, 39 | 40 | 'add-card': self.addCard, 41 | 'add-list': self.addList, 42 | 'add-board': self.addBoard, 43 | 'add-button': self.addButton, 44 | 45 | 'set-card-content': self.setCardContent, 46 | 'get-card-content': self.getCardContent, 47 | 48 | 'set-due-date': self.setDueDate, 49 | 'get-due-date': self.getDueDate, 50 | 'set-due-in': self.setDueIn, 51 | 'move-due-cards': self.moveDueCards, 52 | 53 | 'show-cards': self.showCards, 54 | 'show-lists': self.showLists, 55 | 'show-boards': self.showBoards, 56 | 'show-buttons': self.showButtons, 57 | 58 | 'get-button': self.getButton, 59 | 60 | 'rename-button': self.renameButton, 61 | 'rename-board': self.renameBoard, 62 | 'rename-list': self.renameList, 63 | 'rename-card': self.renameCard, 64 | 65 | 'move-card': self.moveCard, 66 | 'move-list': self.moveList, 67 | 68 | 'shift-card': self.shiftCard, 69 | 'shift-list': self.shiftList, 70 | 'shift-board': self.shiftBoard, 71 | 72 | 'delete-card': self.delCard, 73 | 'delete-list': self.delList, 74 | 'delete-board': self.delBoard, 75 | 'delete-button': self.delButton, 76 | } 77 | return 78 | 79 | def close(self): 80 | self.db.close() 81 | 82 | def initializeDb(self): 83 | print('initializing db') 84 | sqlLines = [ 85 | 'CREATE TABLE boards (title text, idx integer)', 86 | 'CREATE TABLE lists (title text, idx integer, board integer)', 87 | '''CREATE TABLE cards 88 | (title text, 89 | idx integer, 90 | dueDate integer, 91 | list integer, 92 | content text)''', 93 | 'CREATE TABLE buttons (name text, command text, idx integer)', 94 | "INSERT INTO boards VALUES ('Personal', 0)", 95 | """INSERT INTO buttons VALUES 96 | ('Delete card', 'delete-card $CARD', 0)""", 97 | "INSERT INTO lists VALUES ('To do', 0, 1)", 98 | "INSERT INTO lists VALUES ('Doing', 1, 1)", 99 | "INSERT INTO lists VALUES ('Done', 2, 1)", 100 | ] 101 | for sql in sqlLines: 102 | self.db.execute(sql) 103 | 104 | self.db.commit() 105 | return 106 | 107 | def runCommand(self, cmd): 108 | ''' 109 | Executes a command on the datatree 110 | ''' 111 | items = self.actions.items() 112 | op = next(func for verb, func in items if cmd.startswith(verb)) 113 | 114 | # Run command 115 | result = op(cmd) 116 | self.db.commit() 117 | return result 118 | 119 | def where(self, command): 120 | ''' 121 | where 122 | ''' 123 | sql = 'SELECT title FROM boards ORDER BY idx ASC' 124 | result = list(self.db.execute(sql)) 125 | boardName = result[self.boardIdx][0] 126 | return boardName 127 | 128 | def goto(self, command): 129 | ''' 130 | goto 123 131 | goto "board name" 132 | ''' 133 | argPat = r'goto (?P".+"|\d+)' 134 | match = re.match(argPat, command) 135 | boardId = self.getBoardId(match.group('boardStr')) 136 | sql = f''' 137 | SELECT idx, title FROM boards WHERE ROWID = {boardId} 138 | ''' 139 | idx, title = self.db.execute(sql).fetchone() 140 | self.boardIdx = idx 141 | return f'Current board: {title}' 142 | 143 | def getAllBoardIds(self): 144 | sql = 'SELECT ROWID FROM boards' 145 | boardIds = [i[0] for i in self.db.execute(sql)] 146 | return boardIds 147 | 148 | def getAllListIds(self): 149 | sql = 'SELECT ROWID FROM lists' 150 | listIds = [i[0] for i in self.db.execute(sql)] 151 | return listIds 152 | 153 | def cullOrphans(self): 154 | boardIds = self.getAllBoardIds() 155 | boardIdStr = ','.join(str(bid) for bid in boardIds) 156 | boardIdStr = f'({boardIdStr})' 157 | sql = f''' 158 | DELETE FROM lists 159 | WHERE board NOT IN {boardIdStr} 160 | ''' 161 | self.db.execute(sql) 162 | 163 | listIds = self.getAllListIds() 164 | listIdStr = ','.join(str(bid) for bid in listIds) 165 | listIdStr = f'({listIdStr})' 166 | sql = f''' 167 | DELETE FROM cards 168 | WHERE list NOT IN {listIdStr} 169 | ''' 170 | self.db.execute(sql) 171 | return 172 | 173 | def getCurrentBoardId(self): 174 | ''' 175 | current-board-id 176 | ''' 177 | sql = 'SELECT ROWID FROM boards ORDER BY idx ASC' 178 | boards = list(self.db.execute(sql)) 179 | boardName = boards[self.boardIdx][0] 180 | return boardName 181 | 182 | def getListId(self, listStr, boardId=-1): 183 | if boardId == -1: 184 | boardId = self.getCurrentBoardId() 185 | 186 | if D_QUOTE in listStr: 187 | listTitle = encodeForDB(listStr.strip(D_QUOTE)) 188 | sql = f''' 189 | SELECT ROWID 190 | FROM lists 191 | WHERE title='{listTitle}' 192 | AND board={boardId} 193 | ''' 194 | listId = self.db.execute(sql).fetchone()[0] 195 | elif listStr.isdigit(): 196 | sql = f''' 197 | SELECT ROWID 198 | FROM lists 199 | WHERE ROWID={listStr}''' 200 | listId = self.db.execute(sql).fetchone()[0] 201 | else: 202 | raise NotImplementedError('Alphabetical ids not supported yet') 203 | return listId 204 | 205 | def getBoardId(self, boardStr): 206 | if D_QUOTE in boardStr: 207 | boardTitle = boardStr.strip(D_QUOTE) 208 | sql = f''' 209 | SELECT ROWID 210 | FROM boards 211 | WHERE title='{boardTitle}' 212 | ''' 213 | boardId = self.db.execute(sql).fetchone()[0] 214 | elif boardStr.isdigit(): 215 | sql = f''' 216 | SELECT ROWID 217 | FROM boards 218 | WHERE ROWID={boardStr}''' 219 | boardId = self.db.execute(sql).fetchone()[0] 220 | else: 221 | raise NotImplementedError('Alphabetical ids not supported yet') 222 | return boardId 223 | 224 | def getMaxIdx(self, table, field='', fieldVal=''): 225 | if field and fieldVal: 226 | sql = f''' 227 | SELECT MAX(idx) 228 | FROM {table} 229 | WHERE {field}={fieldVal} 230 | ''' 231 | else: 232 | sql = f'SELECT MAX(idx) FROM {table}' 233 | maxIdx = self.db.execute(sql).fetchone()[0] 234 | 235 | if maxIdx is None: 236 | maxIdx = -1 237 | newIdx = maxIdx + 1 238 | return newIdx 239 | 240 | def reindex(self, table, field='', fieldVal=''): 241 | if field and fieldVal: 242 | sql = f''' 243 | SELECT ROWID 244 | FROM {table} 245 | WHERE {field}={fieldVal} 246 | ORDER BY idx ASC 247 | ''' 248 | else: 249 | sql = f''' 250 | SELECT ROWID 251 | FROM {table} 252 | ORDER BY idx ASC 253 | ''' 254 | 255 | rows = self.db.execute(sql) 256 | for idx, row in enumerate(rows): 257 | rowId = row[0] 258 | sql = f''' 259 | UPDATE {table} 260 | SET idx = {idx} 261 | WHERE ROWID = {rowId} 262 | ''' 263 | self.db.execute(sql) 264 | return 265 | 266 | def addCard(self, command): 267 | ''' 268 | add-card "card title":"description":123 to 123 269 | add-card "card title":"description":123 to "list title" 270 | ''' 271 | # Get card title and list title 272 | pat = r'add-card "(.*)":"(.*)":([\d-]*) to (".*"|.*)' 273 | match = re.match(pat, command) 274 | cardTitle = match.group(1) 275 | descStr = match.group(2) 276 | dueDate = match.group(3) 277 | listStr = match.group(4) 278 | 279 | # Get new index 280 | listId = self.getListId(listStr) 281 | newIdx = self.getMaxIdx('cards', 'list', listId) 282 | 283 | # Insert list into table 284 | values = (cardTitle, newIdx, dueDate, listId, descStr) 285 | sql = ''' 286 | INSERT INTO cards(title, idx, dueDate, list, content) 287 | VALUES (?, ?, ?, ?, ?) 288 | ''' 289 | self.db.execute(sql, values) 290 | return 291 | 292 | def addList(self, command): 293 | ''' 294 | add-list "List title" to 123 295 | ''' 296 | # Parse command string 297 | pat = r'add-list "(.*)" to (\d*)' 298 | match = re.match(pat, command) 299 | newListTitle = match.group(1) 300 | boardId = match.group(2) 301 | 302 | # Get new index 303 | newIdx = self.getMaxIdx('lists', 'board', boardId) 304 | 305 | # Insert list into table 306 | values = (newListTitle, newIdx, boardId) 307 | sql = f'INSERT INTO lists(title, idx, board) VALUES {values}' 308 | self.db.execute(sql) 309 | return 310 | 311 | def addBoard(self, command): 312 | ''' 313 | add-board "Board title" 314 | ''' 315 | # Parse command string 316 | pat = r'add-board "(.*)"' 317 | match = re.match(pat, command) 318 | newBoardTitle = match.group(1).strip('"') 319 | 320 | # Get new index 321 | newIdx = self.getMaxIdx('boards') 322 | 323 | # Insert board into table 324 | values = (newBoardTitle, newIdx) 325 | sql = f'INSERT INTO boards(title, idx) VALUES {values}' 326 | self.db.execute(sql) 327 | return 328 | 329 | def addButton(self, command): 330 | ''' 331 | add-button "Button title" "command" 332 | ''' 333 | # Parse command string 334 | pat = r'add-button "(.*)" "(.*)"' 335 | match = re.match(pat, command) 336 | newButtonName = match.group(1).strip('"') 337 | newButtonCommand = match.group(2).strip('"') 338 | 339 | # Get new index 340 | newIdx = self.getMaxIdx('buttons') 341 | 342 | # Insert button into table 343 | values = (newButtonName, newButtonCommand, newIdx) 344 | sql = f'INSERT INTO buttons(name, command, idx) VALUES {values}' 345 | self.db.execute(sql) 346 | return 347 | 348 | def setCardContent(self, command): 349 | ''' 350 | set-card-content 123 to "content" 351 | ''' 352 | pat = r'set-card-content (\d*) "(.*)"' 353 | match = re.match(pat, command) 354 | cardId = match.group(1) 355 | content = match.group(2).strip('"') 356 | content = content.replace('\t', ' '*4) 357 | content = content.replace('\n', '<|NEWLINE|>') 358 | 359 | sql = f''' 360 | UPDATE cards 361 | SET content = '{content}' 362 | WHERE ROWID = {cardId} 363 | ''' 364 | self.db.execute(sql) 365 | return 366 | 367 | def getCardContent(self, command): 368 | ''' 369 | get-card-content 123 370 | ''' 371 | pat = r'get-card-content (\d*)' 372 | match = re.match(pat, command) 373 | cardId = match.group(1) 374 | 375 | sql = f''' 376 | SELECT content 377 | FROM cards 378 | WHERE ROWID = {cardId} 379 | ''' 380 | self.db.execute(sql) 381 | return 382 | 383 | def setDueIn(self, command): 384 | ''' 385 | set-due-in 123 12d/w/m/y 386 | ''' 387 | pat = r'set-due-in (\d+) (\d+d|\d+w|\d+m|\d+y)' 388 | match = re.match(pat, command) 389 | cardId = match.group(1) 390 | interval = match.group(2) 391 | 392 | num = int(interval[:-1]) 393 | unit = interval[-1] 394 | 395 | coefMap = { 396 | 'd': 24*60*60, 397 | 'w': 24*60*60*7, 398 | 'm': 24*60*60*30, 399 | 'y': 24*60*60*365, 400 | } 401 | coef = coefMap[unit] 402 | dueDate = (num*coef) + int(time.time()) 403 | 404 | sql = f''' 405 | UPDATE cards 406 | SET dueDate = {dueDate} 407 | WHERE ROWID = {cardId} 408 | ''' 409 | self.db.execute(sql) 410 | return 411 | 412 | def setDueDate(self, command): 413 | ''' 414 | set-due-date 123 1234561234 415 | ''' 416 | pat = r'set-due-date (\d+) (\d+|-1)' 417 | match = re.match(pat, command) 418 | cardId = match.group(1) 419 | dueDate = match.group(2) 420 | 421 | sql = f''' 422 | UPDATE cards 423 | SET dueDate = {dueDate} 424 | WHERE ROWID = {cardId} 425 | ''' 426 | self.db.execute(sql) 427 | return 428 | 429 | def getDueDate(self, command): 430 | ''' 431 | get-due-date 123 432 | ''' 433 | pat = r'get-due-date (\d*)' 434 | match = re.match(pat, command) 435 | cardId = match.group(1) 436 | 437 | sql = f''' 438 | SELECT dueDate 439 | FROM cards 440 | WHERE ROWID = {cardId} 441 | ''' 442 | self.db.execute(sql) 443 | return 444 | 445 | def moveDueCards(self, command): 446 | ''' 447 | move-due-cards 123,123,123 to 123 448 | ''' 449 | pat = r'move-due-cards ([\d,]+) to (\d+)' 450 | match = re.match(pat, command) 451 | sourceListIds = match.group(1) 452 | destListId = match.group(2) 453 | today = int(time.time()) 454 | 455 | sql = f''' 456 | UPDATE cards 457 | SET list = {destListId} 458 | WHERE list IN ({sourceListIds}) 459 | AND dueDate < {today} 460 | AND dueDate > 0 461 | ''' 462 | self.db.execute(sql) 463 | self.reindex('cards', 'list', destListId) 464 | return 465 | 466 | def renameButton(self, command): 467 | ''' 468 | rename-button 123 "Button title" "command" 469 | ''' 470 | # Parse command string 471 | pat = r'rename-button (\d*) "(.*)" "(.*)"' 472 | match = re.match(pat, command) 473 | 474 | buttonId = match.group(1) 475 | buttonTitle = match.group(2) 476 | buttonCommand = match.group(3) 477 | 478 | sql = f''' 479 | UPDATE buttons 480 | SET name = '{buttonTitle}', 481 | command = '{buttonCommand}' 482 | WHERE ROWID = {buttonId} 483 | ''' 484 | self.db.execute(sql) 485 | 486 | def renameBoard(self, command): 487 | ''' 488 | rename-board 123 "board title" 489 | ''' 490 | # Parse command string 491 | pat = r'rename-board (\d*) "(.*)"' 492 | match = re.match(pat, command) 493 | 494 | boardId = match.group(1) 495 | boardTitle = match.group(2) 496 | 497 | sql = f''' 498 | UPDATE boards 499 | SET title = '{boardTitle}' 500 | WHERE ROWID = {boardId} 501 | ''' 502 | self.db.execute(sql) 503 | 504 | def renameList(self, command): 505 | ''' 506 | rename-list 123 "list title" 507 | ''' 508 | # Parse command string 509 | pat = r'rename-list (\d*) "(.*)"' 510 | match = re.match(pat, command) 511 | 512 | listId = match.group(1) 513 | listTitle = match.group(2) 514 | 515 | sql = f''' 516 | UPDATE lists 517 | SET title = '{listTitle}' 518 | WHERE ROWID = {listId} 519 | ''' 520 | self.db.execute(sql) 521 | 522 | def renameCard(self, command): 523 | ''' 524 | rename-card 123 "Card title" 525 | ''' 526 | # Parse command string 527 | pat = r'rename-card (\d*) "(.*)"' 528 | match = re.match(pat, command) 529 | 530 | cardId = match.group(1) 531 | cardTitle = match.group(2) 532 | 533 | sql = f''' 534 | UPDATE cards 535 | SET title = '{cardTitle}' 536 | WHERE ROWID = {cardId} 537 | ''' 538 | self.db.execute(sql) 539 | 540 | def showCards(self, command): 541 | ''' 542 | show-cards "List title" 543 | show-cards 123 544 | ''' 545 | pat = r'show-cards (".*"|\d*)' 546 | match = re.match(pat, command) 547 | 548 | # Get list id 549 | listStr = match.group(1) 550 | listId = self.getListId(listStr) 551 | 552 | # Get cards in the list 553 | sql = f''' 554 | SELECT ROWID, title, dueDate, content 555 | FROM cards 556 | WHERE list={listId} 557 | ORDER BY idx ASC''' 558 | cards = self.db.execute(sql) 559 | 560 | # Show results 561 | result = 'id\tdue\ttitle\tcontent\n' 562 | for card in cards: 563 | result += f'{card[0]}\t{card[2]}\t{card[1]}\t{card[3] or ""}\n' 564 | return result 565 | 566 | def showLists(self, command): 567 | ''' 568 | show-lists 569 | show-lists "board name" 570 | show-lists 123 571 | ''' 572 | pat = r'show-lists (".*"|\d*)' 573 | match = re.match(pat, command) 574 | 575 | # Get the board id 576 | if match is None: 577 | sql = 'SELECT ROWID FROM boards ORDER BY idx ASC' 578 | boardId = list(self.db.execute(sql))[self.boardIdx][0] 579 | else: 580 | boardStr = match.group(1) 581 | boardId = self.getBoardId(boardStr) 582 | 583 | # Get the lists in that board 584 | sql = f''' 585 | SELECT ROWID, title, idx 586 | FROM lists 587 | WHERE board={boardId} 588 | ORDER BY idx ASC 589 | ''' 590 | lists = self.db.execute(sql) 591 | 592 | # Show the results 593 | result = 'id\ttitle\tcards\n' 594 | for _list in lists: 595 | sql = f"SELECT ROWID FROM cards WHERE list='{_list[0]}'" 596 | cardCount = len(list(self.db.execute(sql))) 597 | result += f'{_list[0]}\t{_list[1]}\t{cardCount}\n' 598 | return result 599 | 600 | def showBoards(self, command): 601 | ''' 602 | show-boards 603 | ''' 604 | sql = ''' 605 | SELECT ROWID, title 606 | FROM boards 607 | ORDER BY idx ASC 608 | ''' 609 | boards = list(self.db.execute(sql)) 610 | 611 | result = 'id\ttitle\n' 612 | for board in boards: 613 | result += f'{board[0]}\t{board[1]}\n' 614 | return result 615 | 616 | def showButtons(self, command): 617 | ''' 618 | show-buttons 619 | ''' 620 | sql = ''' 621 | SELECT ROWID, name, command 622 | FROM buttons 623 | ORDER BY idx ASC 624 | ''' 625 | buttons = list(self.db.execute(sql)) 626 | 627 | result = 'id\tname\tcommand\n' 628 | for button in buttons: 629 | result += f'{button[0]}\t{button[1]}\t{button[2]}\n' 630 | return result 631 | 632 | def getButton(self, command): 633 | ''' 634 | get-button 635 | ''' 636 | argPat = r'get-button (\d*)' 637 | match = re.match(argPat, command) 638 | 639 | buttonId = match.group(1) 640 | sql = f''' 641 | SELECT command 642 | FROM buttons 643 | WHERE ROWID = {buttonId} 644 | ''' 645 | command = self.db.execute(sql).fetchone()[0] 646 | return command 647 | 648 | def listsInBoard(self, boardId): 649 | sql = f'''SELECT ROWID FROM lists 650 | WHERE board = {boardId} ORDER BY idx ASC''' 651 | listsInBoard = [r[0] for r in self.db.execute(sql)] 652 | return listsInBoard 653 | 654 | def moveCard(self, command): 655 | ''' 656 | move-card 123 to "list title" 657 | move-card 123 to "list title" in "board title" 658 | move-card 123 to 132 659 | move-card 123 to next 660 | move-card 123 to prev 661 | ''' 662 | argPat = r'move-card (?P".+"|\d+)' 663 | argPat += r' to (?P".+"|\d+|next|prev)' 664 | argPat += r'(?: in (?P".+"|\d+))?' 665 | match = re.match(argPat, command) 666 | 667 | cardId = match.group('cardStr') 668 | 669 | if match.group('boardStr'): 670 | boardId = self.getBoardId(match.group('boardStr')) 671 | else: 672 | boardId = self.getCurrentBoardId() 673 | 674 | if 'next' in match.group('listDstStr'): 675 | sql = f'SELECT list FROM cards WHERE ROWID = {cardId}' 676 | currentListId = self.db.execute(sql).fetchone()[0] 677 | listsInBoard = self.listsInBoard(boardId) 678 | 679 | listIdx = listsInBoard.index(currentListId) 680 | nextListIdx = min(listIdx + 1, len(listsInBoard) - 1) 681 | listDstId = listsInBoard[nextListIdx] 682 | 683 | elif 'prev' in match.group('listDstStr'): 684 | sql = f'SELECT list FROM cards WHERE ROWID = {cardId}' 685 | currentListId = self.db.execute(sql).fetchone()[0] 686 | listsInBoard = self.listsInBoard(boardId) 687 | 688 | listIdx = listsInBoard.index(currentListId) 689 | prevListIdx = max(listIdx - 1, 0) 690 | listDstId = listsInBoard[prevListIdx] 691 | 692 | else: 693 | listDstId = self.getListId(match.group('listDstStr'), boardId) 694 | 695 | self.reindex('cards', 'list', listDstId) 696 | newIdx = self.getMaxIdx('cards', 'list', listDstId) 697 | sql = f''' 698 | UPDATE cards 699 | SET list = {listDstId}, 700 | idx = {newIdx} 701 | WHERE ROWID = {cardId} 702 | ''' 703 | self.db.execute(sql) 704 | return 705 | 706 | def moveList(self, command): 707 | ''' 708 | move-list "list title" to "board title" 709 | move-list 123 to 123 710 | ''' 711 | argPat = r'move-list (?P".+"|\d+) to (?P".+"|\d+)' 712 | match = re.match(argPat, command) 713 | 714 | listId = self.getListId(match.group('listStr')) 715 | boardId = self.getBoardId(match.group('boardStr')) 716 | sql = f''' 717 | UPDATE lists 718 | SET board = {boardId} 719 | WHERE ROWID = {listId} 720 | ''' 721 | self.db.execute(sql) 722 | return 723 | 724 | def shiftCard(self, command): 725 | ''' 726 | shift-card to 727 | shift-card 123 to 0 728 | ''' 729 | argPat = r'shift-card (\d+) to (\d+|-\d+)' 730 | match = re.match(argPat, command) 731 | cardId = match.group(1) 732 | newIndex = int(match.group(2)) 733 | 734 | sql = f'SELECT list FROM cards WHERE ROWID = {cardId}' 735 | listId = self.db.execute(sql).fetchone()[0] 736 | 737 | # Reindex card in case of corrupted indexes 738 | self.reindex('cards', 'list', listId) 739 | 740 | sql = f'SELECT idx FROM cards WHERE ROWID = {cardId}' 741 | result = self.db.execute(sql).fetchone() 742 | oldIndex = int(result[0]) 743 | 744 | sign = '-' if newIndex > oldIndex else '+' 745 | sql = f''' 746 | UPDATE cards SET idx = idx {sign} 1 747 | WHERE {min(oldIndex, newIndex)} <= idx 748 | AND idx <= {max(oldIndex, newIndex)} 749 | AND list = {listId} 750 | ''' 751 | self.db.execute(sql) 752 | 753 | sql = f''' 754 | UPDATE cards 755 | SET idx = {newIndex} 756 | WHERE ROWID = {cardId} 757 | ''' 758 | self.db.execute(sql) 759 | return 760 | 761 | def shiftList(self, command): 762 | ''' 763 | shift-list to 764 | shift-list 123 to 0 765 | ''' 766 | argPat = r'shift-list (\d+) to (\d+|-\d+)' 767 | match = re.match(argPat, command) 768 | listId = match.group(1) 769 | newIndex = int(match.group(2)) 770 | 771 | sql = f'SELECT board FROM lists WHERE ROWID = {listId}' 772 | boardId = self.db.execute(sql).fetchone()[0] 773 | 774 | # Reindex lists in case of corrupted indexes 775 | self.reindex('lists', 'board', boardId) 776 | 777 | sql = f''' 778 | SELECT idx FROM lists WHERE ROWID = {listId} 779 | ''' 780 | result = self.db.execute(sql).fetchone() 781 | oldIndex = int(result[0]) 782 | 783 | sign = '-' if newIndex > oldIndex else '+' 784 | sql = f''' 785 | UPDATE lists SET idx = idx {sign} 1 786 | WHERE {min(oldIndex, newIndex)} <= idx 787 | AND idx <= {max(oldIndex, newIndex)} 788 | AND board = {boardId} 789 | ''' 790 | self.db.execute(sql) 791 | 792 | sql = f''' 793 | UPDATE lists 794 | SET idx = {newIndex} 795 | WHERE ROWID = {listId} 796 | ''' 797 | self.db.execute(sql) 798 | return 799 | 800 | def shiftBoard(self, command): 801 | ''' 802 | shift-board to 803 | shift-board 123 to 0 804 | ''' 805 | argPat = r'shift-board (\d+) to (\d+|-\d+)' 806 | match = re.match(argPat, command) 807 | boardId = match.group(1) 808 | newIndex = int(match.group(2)) 809 | 810 | # Reindex lists in case of corrupted indexes 811 | self.reindex('boards') 812 | 813 | sql = f''' 814 | SELECT idx FROM boards WHERE ROWID = {boardId} 815 | ''' 816 | result = self.db.execute(sql).fetchone() 817 | oldIndex = int(result[0]) 818 | 819 | sign = '-' if newIndex > oldIndex else '+' 820 | sql = f''' 821 | UPDATE boards SET idx = idx {sign} 1 822 | WHERE {min(oldIndex, newIndex)} <= idx 823 | AND idx <= {max(oldIndex, newIndex)} 824 | ''' 825 | self.db.execute(sql) 826 | 827 | sql = f''' 828 | UPDATE boards 829 | SET idx = {newIndex} 830 | WHERE ROWID = {boardId} 831 | ''' 832 | self.db.execute(sql) 833 | return 834 | 835 | def delCard(self, command): 836 | ''' 837 | delete-card 123 838 | ''' 839 | argPat = r'delete-card (?P\d+)' 840 | match = re.match(argPat, command) 841 | cardId = match.group('cardId') 842 | sql = f''' 843 | DELETE FROM cards 844 | WHERE ROWID = {cardId} 845 | ''' 846 | self.db.execute(sql) 847 | return 848 | 849 | def delList(self, command): 850 | ''' 851 | delete-list 123 852 | ''' 853 | argPat = r'delete-list (?P\d+)' 854 | match = re.match(argPat, command) 855 | listId = match.group('listId') 856 | sql = f''' 857 | DELETE FROM lists 858 | WHERE ROWID = {listId} 859 | ''' 860 | self.db.execute(sql) 861 | self.cullOrphans() 862 | return 863 | 864 | def delBoard(self, command): 865 | ''' 866 | delete-board 123 867 | ''' 868 | argPat = r'delete-board (?P\d+)' 869 | match = re.match(argPat, command) 870 | boardId = match.group('boardId') 871 | sql = f''' 872 | DELETE FROM boards 873 | WHERE ROWID = {boardId} 874 | ''' 875 | self.db.execute(sql) 876 | self.cullOrphans() 877 | return 878 | 879 | def delButton(self, command): 880 | ''' 881 | delete-button 123 882 | ''' 883 | pat = r'delete-button (\d*)' 884 | match = re.match(pat, command) 885 | boardId = match.group(1) 886 | sql = f''' 887 | DELETE FROM buttons 888 | WHERE ROWID = {boardId} 889 | ''' 890 | self.db.execute(sql) 891 | return 892 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------