diff --git a/gui/maingui.go b/gui/maingui.go index f8d8caf..ab591e0 100644 --- a/gui/maingui.go +++ b/gui/maingui.go @@ -1,7 +1,6 @@ package gui import ( - "time" "path/filepath" "fmt" @@ -14,7 +13,7 @@ import ( "github.com/rhaidiz/broxy/util" ) -var broxyTitle = "Broxy (1.0.0-alpha.3)" +var broxyTitle = "Broxy (1.0.0-alpha.4)" // Broxygui is the main GUI made of tabs type Broxygui struct { @@ -58,18 +57,18 @@ func (g *Broxygui) createMenuBar(){ menuBar := g.MenuBar().AddMenu2("&File") newAction := widgets.NewQAction2("New project", g) - saveAction := widgets.NewQAction2("Persist project", g) + //saveAction := widgets.NewQAction2("Persist project", g) openAction := widgets.NewQAction2("Open project...", g) menuBar.AddActions([]*widgets.QAction{}) - menuBar.AddActions([]*widgets.QAction{newAction, saveAction,openAction}) + menuBar.AddActions([]*widgets.QAction{newAction, openAction}) newAction.SetShortcuts2(gui.QKeySequence__New) - saveAction.SetShortcuts2(gui.QKeySequence__SaveAs) + //saveAction.SetShortcuts2(gui.QKeySequence__SaveAs) openAction.SetShortcuts2(gui.QKeySequence__Open) newAction.ConnectTriggered(g.newProjectAction) - saveAction.ConnectTriggered(g.saveProjectAction) + //saveAction.ConnectTriggered(g.saveProjectAction) openAction.ConnectTriggered(g.openProjectAction) } @@ -128,9 +127,15 @@ func (g *Broxygui) saveProjectAction(b bool){ func (g *Broxygui) newProjectAction(b bool){ - p := filepath.Join(util.GetTmpDir(), fmt.Sprintf("%d",time.Now().UnixNano())) - fmt.Println(p) - c, err := project.NewPersistentProject("NewProject",p) + var fileDialog = widgets.NewQFileDialog2(g, "Create new project", "", "") + fileDialog.SetAcceptMode(widgets.QFileDialog__AcceptSave) + if fileDialog.Exec() != int(widgets.QDialog__Accepted) { + return + } + var fn = fileDialog.SelectedFiles()[0] + dir, file := filepath.Split(fn) + + c, err := project.NewPersistentProject(file,dir) if err != nil { g.ShowErrorMessage(fmt.Sprintf("Error while creating project: %s",err)) diff --git a/gui/projectgui.go b/gui/projectgui.go index 263201f..e7b129b 100644 --- a/gui/projectgui.go +++ b/gui/projectgui.go @@ -10,7 +10,7 @@ import ( "github.com/therecipe/qt/core" "github.com/therecipe/qt/gui" "github.com/therecipe/qt/widgets" - "time" + //"time" "path/filepath" ) @@ -141,13 +141,20 @@ func (g *Projectgui) itemDoubleClicked(item *widgets.QListWidgetItem){ func (g *Projectgui) newProject(b bool) { - p := filepath.Join(util.GetTmpDir(), fmt.Sprintf("%d",time.Now().UnixNano())) - c, err := project.NewPersistentProject("NewProject",p) + var fileDialog = widgets.NewQFileDialog2(g, "Create new project", "", "") + fileDialog.SetAcceptMode(widgets.QFileDialog__AcceptSave) + if fileDialog.Exec() != int(widgets.QDialog__Accepted) { + return + } + var fn = fileDialog.SelectedFiles()[0] + dir, file := filepath.Split(fn) + + c, err := project.NewPersistentProject(file,dir) if err != nil { g.showErrorMessage(fmt.Sprintf("Error while creating a new project: %s",err)) } - // temporary, for now, everytime I create a new project I save it in the history + g.history.Add(&project.Project{file,dir}) gui := NewBroxygui(nil,0) s := bcore.NewSession(g.config, c, gui) //Load All modules diff --git a/modules/coreproxy/coreproxy_controller.go b/modules/coreproxy/coreproxy_controller.go index 96b6bf5..fd8d4d7 100644 --- a/modules/coreproxy/coreproxy_controller.go +++ b/modules/coreproxy/coreproxy_controller.go @@ -514,10 +514,11 @@ func (c *Controller) onReq(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Reques } ips, err := net.LookupHost(r.Host) var ip string - if err == nil { + if err != nil { ip = "Unknown host" + }else{ + ip = ips[0] } - ip = ips[0] // this is the original request, save it for the history httpItem.Req = &model.Request{ ID: count + ctx.Session, diff --git a/util/util.go b/util/util.go index 22887da..42b3cbb 100644 --- a/util/util.go +++ b/util/util.go @@ -156,18 +156,7 @@ func GetSettingsDir() string { // GetTmpDir returns the path to a temporary folder func GetTmpDir() string { - if runtime.GOOS == "linux" { - return filepath.Join("/tmp") - } - - if runtime.GOOS == "darwin" { - return filepath.Join("/tmp") - } - - if runtime.GOOS == "windows" { - return filepath.Join(os.Getenv("TEMP")) - } - return "./" + return os.TempDir() } func IsNil(i interface{}) bool {