diff --git a/database.py b/database.py index daf07d0..f9da46e 100644 --- a/database.py +++ b/database.py @@ -46,6 +46,8 @@ def update_job_in_db(old_name, new_name, folder1, folder2, interval): cursor.execute(''' UPDATE jobs SET name = ?, folder1 = ?, folder2 = ?, interval = ? WHERE name = ? ''', (new_name, folder1, folder2, interval, old_name)) + if old_name != new_name: + cursor.execute(f'ALTER TABLE {old_name} RENAME TO {new_name};') conn.commit() conn.close() diff --git a/how_to.gif b/how_to.gif new file mode 100644 index 0000000..99947d3 Binary files /dev/null and b/how_to.gif differ diff --git a/job_item.py b/job_item.py index 5250138..c8d04fa 100644 --- a/job_item.py +++ b/job_item.py @@ -8,7 +8,7 @@ class JobItem(QWidget): self.folder1 = folder1 self.folder2 = folder2 self.interval = interval - self.thread = JobThread(self) + self.setup_thread() self.setup_ui() def setup_ui(self): @@ -33,6 +33,9 @@ class JobItem(QWidget): self.sync_button.clicked.connect(self.run_sync) self.thread.current_log.connect(self.update_log) + def setup_thread(self): + self.thread = JobThread(self) + def toggle_play(self): if self.thread.is_running: self.thread.stop() diff --git a/job_list_widget.py b/job_list_widget.py index 759152c..03fa225 100644 --- a/job_list_widget.py +++ b/job_list_widget.py @@ -106,7 +106,7 @@ class JobListWidget(QWidget): list_item.setSizeHint(job_item.sizeHint()) self.job_list.addItem(list_item) self.job_list.setItemWidget(list_item, job_item) - + self.job_list.setCurrentItem(list_item) job_item.delete_button.clicked.connect(lambda checked, item=list_item: self.delete_job(item)) add_job_to_db(name, folder1, folder2, int(interval)) @@ -129,9 +129,9 @@ class JobListWidget(QWidget): self.interval_edit.setText(str(job_item.interval)) def apply_job(self): - self.selected_items = self.job_list.selectedItems() - if self.selected_items: - job_item = self.job_list.itemWidget(self.selected_items[0]) + self.selected_item = self.job_list.selectedItems()[0] + if self.selected_item: + job_item = self.job_list.itemWidget(self.selected_item) old_name = job_item.name new_name = self.job_name_edit.text() @@ -141,20 +141,24 @@ class JobListWidget(QWidget): if new_name and folder1 and folder2 and interval: # Check if new job name already exists in other jobs - if old_name != new_name and any(self.job_list.itemWidget(self.job_list.item(i)).name == new_name for i in range(self.job_list.count())): + item_cnt = self.job_list.count() + if old_name != new_name and any(self.job_list.itemWidget(self.job_list.item(i)).name == new_name for i in range(item_cnt)): self.window().add_log(f"Job with name '{old_name}' already exists.", QColor('white'), QColor('red')) return - # Update the job item - job_item.name = new_name - job_item.folder1 = folder1 - job_item.folder2 = folder2 - job_item.interval = int(interval) - job_item.name_label.setText(new_name) - # Update the database update_job_in_db(old_name, new_name, folder1, folder2, int(interval)) + # Update the job item + # job_item.name = new_name + # job_item.folder1 = folder1 + # job_item.folder2 = folder2 + # job_item.interval = int(interval) + # job_item.name_label.setText(new_name) + job_item = JobItem(new_name, folder1, folder2, int(interval)) + job_item.delete_button.clicked.connect(lambda checked, item=self.selected_item: self.delete_job(item)) + self.job_list.setItemWidget(self.selected_item, job_item) + self.window().add_log(f'Clicked \'Apply Job\' - ({job_item.name}) !', QColor('yellow'), QColor('green')) def load_jobs_from_db(self): diff --git a/job_thread.py b/job_thread.py index e9b3b0e..9072fc3 100644 --- a/job_thread.py +++ b/job_thread.py @@ -27,4 +27,4 @@ class JobThread(QThread): def sync(self): log = self.synchronizer.sync_folders() - self.current_log.emit(log, QColor("yellow"), QColor("green")) \ No newline at end of file + self.current_log.emit(log, QColor("white"), QColor("green")) \ No newline at end of file