Skip to content

Commit

Permalink
VMware model to organize projects. Topology files have the .gns3
Browse files Browse the repository at this point in the history
extension instead of .net (which are still supported).
Bump version to alpha3.
  • Loading branch information
grossmj committed May 2, 2014
1 parent a70c361 commit 9f6b1ac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
51 changes: 34 additions & 17 deletions gns3/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions gns3/preferences_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion gns3/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
number has been incremented)
"""

__version__ = "1.0a3.dev3"
__version__ = "1.0-alpha3"
__version_info__ = (1, 0, 0, -99)

0 comments on commit 9f6b1ac

Please sign in to comment.