From 9f6b1ac212c944cdac1d7caac6c94caa9c832949 Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 2 May 2014 15:40:42 -0600 Subject: [PATCH] VMware model to organize projects. Topology files have the .gns3 extension instead of .net (which are still supported). Bump version to alpha3. --- gns3/main_window.py | 51 +++++++++++++++++++++++++------------- gns3/preferences_dialog.py | 16 ++++++------ gns3/version.py | 2 +- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/gns3/main_window.py b/gns3/main_window.py index 79a20f0fd..7d1cfb1ec 100644 --- a/gns3/main_window.py +++ b/gns3/main_window.py @@ -263,8 +263,11 @@ def _openProjectActionSlot(self): Slot called to open a project. """ - directory = self._settings["projects_path"] - path = QtGui.QFileDialog.getOpenFileName(self, "Open project", directory) + path, _ = QtGui.QFileDialog.getOpenFileNameAndFilter(self, + "Open project", + self._settings["projects_path"], + "All files (*.*);;GNS3 project files (*.gns3);;NET files (*.net)", + "GNS3 project files (*.gns3)") if path and self.checkForUnsavedChanges(): self._loadProject(path) @@ -726,7 +729,7 @@ def checkForUnsavedChanges(self): if self.testAttribute(QtCore.Qt.WA_WindowModified): if self._temporary_project: - destination_file = "untitled.net" + destination_file = "untitled.gns3" else: destination_file = os.path.basename(self._project_path) reply = QtGui.QMessageBox.warning(self, "Unsaved changes", 'Save changes to project "{}" before closing?'.format(destination_file), @@ -820,6 +823,8 @@ def startupLoading(self): def _saveProjectAs(self): """ Saves a project to another location/name. + + :returns: GNS3 project file (.gns3) """ # first check if any node that can be started is running @@ -835,19 +840,29 @@ def _saveProjectAs(self): return if self._temporary_project: - destination_file = os.path.join(self._settings["projects_path"], "untitled.net") + default_project_name = "untitled" else: - destination_file = os.path.join(self._settings["projects_path"], os.path.basename(self._project_path)) - path = QtGui.QFileDialog.getSaveFileName(self, "Save project", destination_file, "NET File (*.net)") - if not path: + default_project_name = os.path.basename(self._project_path) + if default_project_name.endswith(".gns3"): + default_project_name = default_project_name[:-5] + + file_dialog = QtGui.QFileDialog(self) + file_dialog.setWindowTitle("Save project") + file_dialog.setNameFilters(["Directories"]) + file_dialog.setDirectory(self._settings["projects_path"]) + file_dialog.setFileMode(QtGui.QFileDialog.AnyFile) + file_dialog.setDefaultSuffix("gns3") + file_dialog.setLabelText(QtGui.QFileDialog.FileName, "Project name:") + file_dialog.selectFile(default_project_name) + file_dialog.setOptions(QtGui.QFileDialog.ShowDirsOnly) + file_dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) + if file_dialog.exec_() == QtGui.QFileDialog.Rejected: return False - new_project_files_dir = path - if path.endswith(".net"): - new_project_files_dir = path[:-4] - else: - path = path + ".net" - new_project_files_dir += "-files" + project_dir = file_dialog.selectedFiles()[0] + project_name = os.path.basename(project_dir)[:-5] + topology_file_path = os.path.join(project_dir, project_name + ".gns3") + new_project_files_dir = os.path.join(project_dir, project_name + "-files") # create the destination directory for project files try: @@ -895,7 +910,7 @@ def _saveProjectAs(self): self._deleteTemporaryProject() self._project_files_dir = new_project_files_dir - return self._saveProject(path) + return self._saveProject(topology_file_path) def _saveProject(self, path): """ @@ -928,7 +943,9 @@ def _loadProject(self, path): self.uiGraphicsView.reset() project_files_dir = path - if path.endswith(".net"): + if path.endswith(".gns3"): + project_files_dir = path[:-5] + elif path.endswith(".net"): project_files_dir = path[:-4] self._project_files_dir = project_files_dir + "-files" @@ -975,9 +992,9 @@ def _createTemporaryProject(self): self.uiGraphicsView.reset() try: - with tempfile.NamedTemporaryFile(prefix="gns3-", suffix=".net", delete=False) as f: + with tempfile.NamedTemporaryFile(prefix="gns3-", suffix=".gns3", delete=False) as f: log.info("creating temporary topology file: {}".format(f.name)) - project_files_dir = f.name[:-4] + "-files" + project_files_dir = f.name[:-5] + "-files" if not os.path.isdir(project_files_dir): log.info("creating temporary project files directory: {}".format(project_files_dir)) os.mkdir(project_files_dir) diff --git a/gns3/preferences_dialog.py b/gns3/preferences_dialog.py index 089d678ba..a3d7240ba 100644 --- a/gns3/preferences_dialog.py +++ b/gns3/preferences_dialog.py @@ -70,14 +70,16 @@ def _loadPreferencePages(self): self.uiStackedWidget.addWidget(servers_page) self._items.append(item) + # Deactivate cloud settings page for alpha3 release + # load cloud settings page - cloud_page = CloudPreferencesPage() - cloud_page.loadPreferences() - name = cloud_page.windowTitle() - item = QtGui.QListWidgetItem(name, self.uiListWidget) - item.setData(QtCore.Qt.UserRole, cloud_page) - self.uiStackedWidget.addWidget(cloud_page) - self._items.append(item) + #cloud_page = CloudPreferencesPage() + #cloud_page.loadPreferences() + #name = cloud_page.windowTitle() + #item = QtGui.QListWidgetItem(name, self.uiListWidget) + #item.setData(QtCore.Qt.UserRole, cloud_page) + #self.uiStackedWidget.addWidget(cloud_page) + #self._items.append(item) # load module preference pages for module in MODULES: diff --git a/gns3/version.py b/gns3/version.py index 041c2b100..cf3d34438 100644 --- a/gns3/version.py +++ b/gns3/version.py @@ -25,5 +25,5 @@ number has been incremented) """ -__version__ = "1.0a3.dev3" +__version__ = "1.0-alpha3" __version_info__ = (1, 0, 0, -99)