def start_synchronization(self):
        self.button_box.button(QDialogButtonBox.Save).setEnabled(False)
        qfield_folder = self.qfieldDir.text()
        self.preferences.set_value('importDirectoryProject', qfield_folder)
        try:
            current_import_file_checksum = import_file_checksum(qfield_folder)
            imported_files_checksums = import_checksums_of_project(
                qfield_folder)

            if imported_files_checksums and current_import_file_checksum and current_import_file_checksum in imported_files_checksums:
                message = self.tr(
                    "Data from this file are already synchronized with the original project."
                )
                raise NoProjectFoundError(message)
            qgs_file = get_project_in_folder(qfield_folder)
            open_project(qgs_file)
            self.offline_editing.progressStopped.connect(self.update_done)
            self.offline_editing.layerProgressUpdated.connect(
                self.update_total)
            self.offline_editing.progressModeSet.connect(self.update_mode)
            self.offline_editing.progressUpdated.connect(self.update_value)
            self.offline_editing.synchronize()
            if self.offline_editing_done:
                original_project_path = ProjectConfiguration(
                    QgsProject.instance()).original_project_path
                if original_project_path:
                    # import the DCIM folder
                    copy_images(
                        os.path.join(qfield_folder, "DCIM"),
                        os.path.join(os.path.dirname(original_project_path),
                                     "DCIM"))
                    if open_project(original_project_path):
                        # save the data_file_checksum to the project and save it
                        imported_files_checksums.append(
                            import_file_checksum(qfield_folder))
                        ProjectConfiguration(QgsProject.instance(
                        )).imported_files_checksums = imported_files_checksums
                        QgsProject.instance().write()
                        self.iface.messageBar().pushInfo(
                            'QFieldSync',
                            self.tr("Opened original project {}".format(
                                original_project_path)))
                    else:
                        self.iface.messageBar().pushInfo(
                            'QFieldSync',
                            self.
                            tr("The data has been synchronized successfully but the original project ({}) could not be opened"
                               .format(original_project_path)))
                else:
                    self.iface.messageBar().pushInfo(
                        'QFieldSync',
                        self.tr("No original project path found"))
                self.close()
            else:
                message = self.tr(
                    "The project you imported does not seem to be an offline project"
                )
                raise NoProjectFoundError(message)
        except NoProjectFoundError as e:
            self.iface.messageBar().pushWarning('QFieldSync', str(e))
Beispiel #2
0
    def start_synchronization(self):
        qfield_folder = self.qfieldDir.text()
        try:
            self.progress_group.setEnabled(True)
            current_import_file_checksum = import_file_checksum(qfield_folder)
            imported_files_checksums = import_checksums_of_project(
                qfield_folder)

            if imported_files_checksums and current_import_file_checksum in imported_files_checksums:
                message = self.tr(
                    "Data from this file are already synchronized with the original project."
                )
                raise NoProjectFoundError(message)
            qgs_file = get_project_in_folder(qfield_folder)
            open_project(qgs_file)
            self.offline_editing.progressStopped.connect(self.update_done)
            self.offline_editing.layerProgressUpdated.connect(
                self.update_total)
            self.offline_editing.progressModeSet.connect(self.update_mode)
            self.offline_editing.progressUpdated.connect(self.update_value)
            self.offline_editing.synchronize()
            if self.offline_editing_done:
                original_project_path = ProjectConfiguration(
                    QgsProject.instance()).original_project_path
                if original_project_path:
                    if open_project(original_project_path):
                        # save the data_file_checksum to the project and save it
                        imported_files_checksums.append(
                            import_file_checksum(qfield_folder))
                        ProjectConfiguration(QgsProject.instance(
                        )).imported_files_checksums = imported_files_checksums
                        QgsProject.instance().write()
                        self.iface.messageBar().pushInfo(
                            'QFieldSync',
                            self.tr(u"Opened original project {}".format(
                                original_project_path)))
                        print(imported_files_checksums)
                    else:
                        self.iface.messageBar().pushInfo(
                            'QFieldSync',
                            self.
                            tr(u"The data has been synchronized successfully but the original project ({}) could not be opened. "
                               .format(original_project_path)))
                self.close()
            else:
                message = self.tr(
                    "The project you imported does not seem to be "
                    "an offline project")
                raise NoProjectFoundError(message)
        except NoProjectFoundError as e:
            self.iface.messageBar().pushWarning('QFieldSync', str(e))
        finally:
            self.progress_group.setEnabled(False)
Beispiel #3
0
 def start_synchronization(self):
     qfield_folder = self.qfieldDir.text()
     try:
         self.progress_group.setEnabled(True)
         qgs_file = get_project_in_folder(qfield_folder)
         open_project(qgs_file)
         self.offline_editing.progressStopped.connect(self.update_done)
         self.offline_editing.layerProgressUpdated.connect(self.update_total)
         self.offline_editing.progressModeSet.connect(self.update_mode)
         self.offline_editing.progressUpdated.connect(self.update_value)
         self.offline_editing.synchronize()
         if self.offline_editing_done:
             self.close()
         else:
             message = self.tr("The project you imported does not seem to be "
                               "an offline project")
             raise NoProjectFoundError(message)
     except NoProjectFoundError as e:
         self.iface.messageBar().pushWarning('Sync dialog', unicode(e))
     finally:
         self.progress_group.setEnabled(False)
Beispiel #4
0
def get_project_in_folder(folder):
    try:
        return get_children_with_extension(folder, 'qgs', count=1)[0]
    except QFieldSyncError:
        message = 'No .qgs file found in folder {}'.format(folder)
        raise NoProjectFoundError(message)