2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 private import ui
.Installer
;
36 private import ui
.gtkDLogo
;
38 private import gtk
.GtkD
;
39 private import gtk
.Alignment
;
40 private import gtk
.MainWindow
;
41 private import gtk
.VBox
;
42 private import gtk
.HBox
;
43 private import gtk
.Button
;
44 private import gtk
.Label
;
45 private import gtk
.Frame
;
46 private import gtk
.ButtonBox
;
47 private import gtk
.HButtonBox
;
48 private import gtk
.Entry
;
49 private import gtk
.CheckButton
;
50 private import gtk
.Notebook
;
51 private import gtk
.Widget
;
52 private import gtk
.Image
;
53 private import gtkc
.gtktypes
;
54 private import gtk
.SizeGroup
;
55 private import gtk
.HSeparator
;
56 private import gtk
.PopupBox
;
58 private import gtkc
.gtktypes
;
60 private import gdk
.Event
;
61 private import std
.stdio
;
62 private import std
.process
;
63 private import std
.string
;
65 private import std
.c
.stdlib
;
69 void setUserPanel(UserPanel panel
);
70 void addSelection(char[] id
, CheckButton check
);
71 CheckButton
getSelectionButton(char[] id
);
72 bool getSelection(char[] id
);
73 void setSelection(char[] id
, bool state
);
74 void setSensitive(char[] id
, bool state
);
76 void addDirectory(char[] id
, Entry entry
);
77 char[] getDirectory(char[] id
);
78 void setDirectory(char[] id
, char[] value
);
84 public class MainInstaller
: MainWindow
, InstallerUI
99 UserPanel
[] userPanels
;
100 UserPanel currentUserPanel
;
101 CheckButton
[char[]] selections
;
102 Entry
[char[]] directories
;
104 int movingDirection
; // going back or next, 0=don't know
110 super("GtkD and Leds installer");
114 super("GtkD installer");
122 public void addSelection(char[] id
, CheckButton check
)
124 selections
[id
] = check
;
127 public CheckButton
getSelectionButton(char[] id
)
130 if ( id
in selections
)
132 check
= selections
[id
];
137 public bool getSelection(char[] id
)
139 if ( id
in selections
)
141 return cast(bool)selections
[id
].getActive();
145 public void setSelection(char[] id
, bool active
)
147 if ( id
in selections
)
149 selections
[id
].setActive(active
);
152 public void setSensitive(char[] id
, bool active
)
154 if ( id
in selections
)
156 selections
[id
].setSensitive(active
);
160 public void addDirectory(char[] id
, Entry entry
)
162 directories
[id
] = entry
;
164 public char[] getDirectory(char[] id
)
166 if ( id
in directories
)
168 return directories
[id
].getText();
172 public void setDirectory(char[] id
, char[] value
)
174 if ( id
in directories
)
176 return directories
[id
].setText(value
);
180 public void nextPanel()
184 setUserPanel(notebook
.getCurrentPage());
187 public void prevPanel()
189 movingDirection
= -1;
191 setUserPanel(notebook
.getCurrentPage());
196 topBox
= new HBox(false, 2);
197 leftBox
= new VBox(false, 7);
198 tasksBox
= new VBox(false, 7);
199 mainBox
= new VBox(false, 2);
200 notebook
= new Notebook
;
201 notebook
.setShowTabs(false);
202 notebook
.setSizeRequest(400,300);
203 buttonBox
= HButtonBox
.createActionBox();
205 exitButton
= makeButton(null, StockID
.QUIT
, "Exit", "exit");
206 buttonBox
.packStart(Alignment
.west(exitButton
), true, true, 7);
210 backButton
= makeButton(buttonBox
, StockID
.GO_BACK
, "<< Back", "back");
211 nextButton
= makeButton(buttonBox
, StockID
.GO_FORWARD
, "Next >>", "next");
212 installButton
= makeButton(buttonBox
, StockID
.OK
, "Install", "install");
216 backButton
= makeButton(buttonBox
, StockID
.GO_BACK
, "Back", "back");
217 nextButton
= makeButton(buttonBox
, StockID
.GO_FORWARD
, "Next", "next");
218 installButton
= makeButton(buttonBox
, StockID
.OK
, "Install", "install");
221 // Button logo = new Button();
222 // logo.setImage(getGtkDLogo());
223 // logo.addOnButtonPress(&logoClicked);
224 // logo.setRelief(ReliefStyle.NONE);
225 // logo.setFocusOnClick(false);
227 mainBox
.packStart(Alignment
.west(getGtkDLogo()), false, false, 2);
228 mainBox
.packStart(notebook
, true, true, 2);
229 mainBox
.packStart(buttonBox
, false, false, 2);
231 topBox
.packStart(new Frame(tasksBox
,""), false, false, 2);
232 topBox
.packStart(mainBox
, true, true, 2);
237 private int logoClicked(GdkEventButton
* event
, Widget widget
)
240 PopupBox
.information(this, "Help with the graphics design is apreciated", "GtkDLogo");
244 private Button
makeButton(ButtonBox box
,StockID id
, char[] label
, char[] action
)
246 Button button
= new Button();
247 button
.setActionName(action
);
249 button
.setImage(new Image(id
, IconSize
.BUTTON
));
250 button
.setLabel(label
);
253 box
.packStart(button
, false, false, 7);
255 button
.addOnClicked(&userActions
);
259 private void addPanels()
261 addPanel(new SelectionsPanel(this));
262 version(gtkDdev
)addPanel(new DevPanel(this));
263 version(leds
) addPanel(new LedsPanel(this));
264 version(compiler
) addPanel(new MainCompilerPanel(this));
265 addPanel(new LocalPanel(this));
266 addPanel(new InstallPanel(this));
267 addPanel(new TestPanel(this));
270 CheckButton
[char[]] tasksList
;
272 private void addPanel(UserPanel userPanel
)
274 notebook
.appendPage(userPanel
.getWidget(), userPanel
.getName());
276 if ( userPanel
.getName().length
> 0 )
278 HBox hbox
= new HBox(false, 1);
279 CheckButton check
= new CheckButton();
280 hbox
.packStart(check
, false, false, 4);
281 hbox
.packStart(Alignment
.west(new Label(userPanel
.getName())), false, false, 4);
282 tasksBox
.packStart(hbox
, false, false, 4);
283 tasksList
[userPanel
.getName()] = check
;
284 check
.setSensitive(false);
286 userPanels
~= userPanel
;
289 private void userActions(Button button
)
291 char[] action
= button
.getActionName();
313 writefln("userAction = %s", action
);
319 private void setUserPanel(uint number
)
321 if ( number
< userPanels
.length
)
323 UserPanel panel
= userPanels
[number
];
328 public void setUserPanel(UserPanel panel
)
330 if ( currentUserPanel
!is null )
332 currentUserPanel
.exited();
334 while ( !panel
.selected()
335 && movingDirection
!= 0
338 if ( movingDirection
> 0 )
348 backButton
.setSensitive(panel
.allowBack());
349 nextButton
.setSensitive(panel
.allowNext());
350 bool allowInstall
= true;
351 foreach ( UserPanel userPanel
; userPanels
)
353 if ( !userPanel
.complete() )
355 allowInstall
= false;
357 if ( userPanel
.getName
in tasksList
)
359 tasksList
[userPanel
.getName()].setActive(userPanel
.complete());
362 installButton
.setSensitive(allowInstall
);
363 currentUserPanel
= panel
;
369 InstallerUI installerUI
;
371 bool completed
= false;
375 abstract Widget
getWidget();
376 abstract char[] getName();
377 public this(InstallerUI installerUI
)
379 this.installerUI
= installerUI
;
382 public bool allowNext()
386 public bool allowBack()
390 public bool selected()
398 public bool complete()
403 protected HBox
newSelection(char[] selection
, char[] id
)
405 HBox box
= new HBox(false, 2);
407 Button button
= new Button(StockID
.HELP
, &userHelp
, true);
408 button
.setActionName(id
);
409 button
.setImage(new Image(StockID
.HELP
, IconSize
.MENU
));
410 CheckButton check
= new CheckButton(selection
, &userSelection
);
411 check
.setActionName(id
);
413 box
.packStart(button
, false, false, 2);
414 box
.packStart(check
, false, false, 2);
415 installerUI
.addSelection(id
, check
);
419 protected HBox
newDirectory(char[] label
, char[] id
, SizeGroup sizeGroup
)
421 HBox box
= new HBox(false, 2);
422 Button button
= new Button(StockID
.HELP
, &userHelp
, true);
423 button
.setActionName(id
);
424 button
.setImage(new Image(StockID
.HELP
, IconSize
.MENU
));
425 Entry entry
= new Entry();
427 box
.packStart(button
, false, false, 2);
428 Label l
= new Label(label
);
429 Alignment alig
= Alignment
.west(l
);
430 sizeGroup
.addWidget(alig
);
431 box
.packStart(alig
, false, false, 2);
432 box
.packStart(entry
, true, true, 2);
433 button
= new Button(StockID
.INDEX
, &userDirectory
);
434 button
.setActionName(id
);
435 button
.setLabel("Browse");
436 button
.setImage(new Image(StockID
.INDEX
, IconSize
.MENU
));
437 box
.packStart(button
, false, false, 2);
438 installerUI
.addDirectory(id
, entry
);
442 protected HBox
newButton(Button actionButton
, char[] id
)
444 HBox box
= new HBox(false, 2);
446 Button button
= new Button(StockID
.HELP
, &userHelp
, true);
447 button
.setActionName(id
);
448 button
.setImage(new Image(StockID
.HELP
, IconSize
.MENU
));
450 box
.packStart(button
, false, false, 2);
451 box
.packStart(actionButton
, false, false, 2);
455 void userSelection(CheckButton check
)
457 switch ( check
.getActionName() )
461 bool active
= cast(bool)check
.getActive();
462 installerUI
.setSensitive("ledsGtkD", active
);
463 installerUI
.setSensitive("ledsLeds", active
);
464 installerUI
.setSensitive("ledsDool", active
);
465 installerUI
.setSensitive("ledsDante", active
);
466 installerUI
.setSensitive("ledsPhobos", active
);
475 void userHelp(Button button
)
479 private import gtk
.FileChooserDialog
;
480 private import gtk
.FileChooser
;
481 void userDirectory(Button button
)
483 char[] id
= button
.getActionName();
484 char[] dir
= installerUI
.getDirectory(id
);
487 FileChooserDialog chooserDialog
= new FileChooserDialog(
490 FileChooserAction
.SELECT_FOLDER
492 FileChooser chooser
= chooserDialog
.getFileChooser();
493 chooser
.setCurrentFolder(dir
);
494 ResponseType response
= cast(ResponseType
)chooserDialog
.run();
495 if ( response
== ResponseType
.GTK_RESPONSE_OK
)
497 installerUI
.setDirectory(id
, chooser
.getCurrentFolder());
499 chooserDialog
.hide(); // is it released ?
504 class SelectionsPanel
: UserPanel
508 public this(InstallerUI installerUI
)
512 public char[] getName()
516 public Widget
getWidget()
520 vbox
= new VBox(false, 2);
526 public bool allowBack()
531 public bool selected()
539 vbox
.packStart(new Label("Select the components to install"), false, false, 14);
540 vbox
.packStart(newSelection("Install GtkD", "gtkD"), false, false, 2);
541 version(gtkDdev
) vbox
.packStart(newSelection("Install GtkD for development", "gtkDDev"), false, false, 2);
542 version(gtkDgl
) vbox
.packStart(newSelection("Install GtkDgl", "gtkDgl"), false, false, 2);
543 version(gtkDdev
) version(gtkDgl
) vbox
.packStart(newSelection("Install GtkDgl for development", "duiglDev"), false, false, 2);
544 version(leds
) vbox
.packStart(newSelection("Install Leds", "leds"), false, false, 2);
546 installerUI
.setSelection("gtkD", true);
547 version(gtkDdev
) installerUI
.setSelection("gtkDDev", true);
548 version(gtkDgl
) installerUI
.setSelection("gtkDgl", true);
549 version(gtkDdev
) version(gtkDgl
) installerUI
.setSelection("duiglDev", true);
550 version(leds
) installerUI
.setSelection("leds", true);
556 class DevPanel
: UserPanel
560 public this(InstallerUI installerUI
)
564 public char[] getName()
566 return "GtkD Development";
568 public Widget
getWidget()
572 vbox
= new VBox(false, 2);
578 public bool selected()
581 return installerUI
.getSelection("gtkDDev")
582 || installerUI
.getSelection("gtkDglDev");
587 vbox
.packStart(new Label("Select GtkD modules"), false, false, 14);
588 version(difiles
) vbox
.packStart(newSelection("GtkD .di files", "gtkDdi"), false, false, 2);
589 vbox
.packStart(newSelection("GtkD source files", "gtkDSource"), false, false, 2);
590 vbox
.packStart(newSelection("GtkDTests - general UI tests", "gtkDTests"), false, false, 2);
591 version(gtkDgl
) vbox
.packStart(newSelection("SimpleGL - simplest GL test", "gtkDglSimple"), false, false, 2);
592 version(gtkDgl
) vbox
.packStart(newSelection("ShapesGL - showing more of openGL integration", "gtkDglShapes"), false, false, 2);
594 version(difiles
) installerUI
.setSelection("gtkDdi", true);
595 installerUI
.setSelection("gtkDSource", true);
596 installerUI
.setSelection("gtkDTests", true);
597 version(gtkDgl
) installerUI
.setSelection("gtkDglSimple", true);
598 version(gtkDgl
) installerUI
.setSelection("gtkDglShapes", true);
605 class LedsPanel
: UserPanel
609 public this(InstallerUI installerUI
)
613 public char[] getName()
615 return "Leds projects";
617 public Widget
getWidget()
621 vbox
= new VBox(false, 2);
627 public bool selected()
630 return installerUI
.getSelection("leds");
635 vbox
.packStart(new Label("Select the leds projects to create"), false, false, 14);
636 vbox
.packStart(newSelection("Create a leds project for GtkD", "ledsGtkD"), false, false, 2);
637 vbox
.packStart(newSelection("Create a leds project for Leds", "ledsLeds"), false, false, 2);
638 vbox
.packStart(newSelection("Create a leds project for Dool", "ledsDool"), false, false, 2);
639 vbox
.packStart(newSelection("Create a leds project for Dante", "ledsDante"), false, false, 2);
640 vbox
.packStart(newSelection("Create a leds project for phobos", "ledsPhobos"), false, false, 2);
642 installerUI
.setSelection("ledsGtkD", true);
643 installerUI
.setSelection("ledsLeds", true);
644 installerUI
.setSelection("ledsDool", true);
645 installerUI
.setSelection("ledsDante", true);
646 installerUI
.setSelection("ledsPhobos", true);
653 class MainCompilerPanel
: UserPanel
657 public this(InstallerUI installerUI
)
661 public char[] getName()
665 public Widget
getWidget()
669 vbox
= new VBox(false, 2);
675 public bool selected()
683 vbox
.packStart(new Label("Select your D compiler"), false, false, 14);
685 vbox
.packStart(new Label("For the installation"), false, false, 7);
686 vbox
.packStart(newSelection("Digital Mars DMD", "instalCompilerDMD"), false, false, 2);
687 vbox
.packStart(newSelection("gnu D GDC", "installCompilerGDC"), false, false, 2);
689 vbox
.packStart(new Label("For your leds projects"), false, false, 7);
690 vbox
.packStart(newSelection("Digital Mars DMD", "ledsCompilerDMD"), false, false, 2);
691 vbox
.packStart(newSelection("gnu D GDC", "ledsCompilerGDC"), false, false, 2);
693 installerUI
.setSelection("instalCompilerDMD", true);
694 installerUI
.setSelection("installCompilerGDC", false);
695 version(leds
) installerUI
.setSelection("ledsCompilerDMD", true);
696 version(leds
) installerUI
.setSelection("ledsCompilerGDC", false);
698 installerUI
.setSensitive("instalCompilerDMD", false);
699 installerUI
.setSensitive("installCompilerGDC", false);
700 version(leds
) installerUI
.setSensitive("ledsCompilerDMD", false);
701 version(leds
) installerUI
.setSensitive("ledsCompilerGDC", false);
708 class LocalPanel
: UserPanel
715 public this(InstallerUI installerUI
)
718 sizeGroup
= new SizeGroup(SizeGroupMode
.HORIZONTAL
);
721 home
= std
.string
.toString(getenv("HOMEPATH"));
725 home
= std
.string
.toString(getenv("HOME"));
729 public char[] getName()
734 private import std
.path
;
735 private import std
.file
;
737 private bool validDir(char[] dir
)
739 bool valid
= dir
.length
> 0;
743 public bool validDMDHome()
746 char[] dir
= installerUI
.getDirectory("dmdHome");
747 valid
= validDir(dir
);
752 version(Win32
) char[] dmd
= std
.path
.join(std
.path
.join(dir
,"bin"), "dmd.exe");
753 else char[] dmd
= std
.path
.join(std
.path
.join(dir
,"bin"), "dmd");
754 std
.file
.isfile(dmd
);
757 char[] dm
= std
.path
.join(std
.path
.join(dir
,"..\\dm"),"bin");
758 char[] link
= std
.path
.join(dm
, "link.exe");
759 std
.file
.isfile(link
);
760 char[] lib
= std
.path
.join(dm
, "lib.exe");
761 std
.file
.isfile(lib
);
763 else char[] link
= std
.path
.join(std
.path
.join(dir
,"bin"), "dmd");
766 catch ( FileException pe
)
779 // char[] userChoice;
783 // bool isDir(char[] dir)
788 // ok = cast(bool)std.file.isfile(dir);
790 // catch ( FileException fe )
797 // bool exists(char[] fileName)
802 // ok = cast(bool)std.file.exists(fileName);
804 // catch ( FileException fe )
812 public char[] guessDMDHome()
821 guess
= std
.path
.join(home
, "dmd");
826 public char[] guessGtkHome()
831 guess
= "\\Program Files\\Common Files\\GTK\\2.0\\bin";
840 public char[] guessGtkDLibHome()
845 guess
= "\\Program Files\\Common Files\\GTK\\2.0\\bin";
849 guess
= "/home/ruimt/usr/lib";
854 public char[] guessGtkDDevHome()
859 guess
= "\\testRelease";
863 guess
= std
.path
.join(home
, "devel/D/testInstall/GtkD1");
868 public char[] guessLedsHome()
873 guess
= "\\Program Files\\Common Files\\org\\dsource\\leds";
877 guess
= std
.path
.join(home
, "devel/D/Leds1");
883 public bool selected()
890 completed
= validDMDHome();
897 completed
= installerUI
.getDirectory("gtkDDevHome").length
> 0;
904 completed
= installerUI
.getDirectory("ledsHome").length
> 0;
910 completed
= installerUI
.getDirectory("gtkHome").length
> 0;
914 completed
= installerUI
.getDirectory("gtkDLibHome").length
> 0;
919 public Widget
getWidget()
923 vbox
= new VBox(false, 2);
930 vbox
.packStart(new Label("Select the paths for installation"), false, false, 14);
931 vbox
.packStart(newDirectory("DMD home", "dmdHome", sizeGroup
), false, false, 2);
932 vbox
.packStart(newDirectory("Gtk lib home", "gtkHome", sizeGroup
), false, false, 2);
933 vbox
.packStart(newDirectory("GtkD lib home", "gtkDLibHome", sizeGroup
), false, false, 2);
934 version(gtkDdev
) vbox
.packStart(newDirectory("GtkD dev home", "gtkDDevHome", sizeGroup
), false, false, 2);
935 version(leds
) vbox
.packStart(newDirectory("leds home", "ledsHome", sizeGroup
), false, false, 2);
937 installerUI
.setDirectory("dmdHome", guessDMDHome());
938 installerUI
.setDirectory("gtkHome", guessGtkHome());
939 installerUI
.setDirectory("gtkDLibHome", guessGtkDLibHome());
940 version(gtkDdev
) installerUI
.setDirectory("gtkDDevHome", guessGtkDDevHome());
941 version(leds
) installerUI
.setDirectory("ledsHome", guessLedsHome());
945 class InstallPanel
: UserPanel
948 //bool installed = false;
949 public this(InstallerUI installerUI
)
953 public bool selected()
958 public char[] getName()
962 public Widget
getWidget()
966 vbox
= new VBox(false, 2);
979 Label label
= new Label(
980 "Thank you for installing GtkD\n"
981 ~"press Install to continue"
983 vbox
.packStart(label
, true, true, 2);
985 version(gtkDtest
) vbox
.packStart(newSelection("Create desktop icon for gtkD tests", "gtkDTestsIcon"), false, false, 2);
986 version(leds
) vbox
.packStart(newSelection("Create desktop icon for leds", "ledsIcon"), false, false, 2);
987 version(leds
) vbox
.packStart(newSelection("set leds as your D editor", "ledsDEditor"), false, false, 2);
989 version(gtkDtest
) installerUI
.setSelection("gtkDTestsIcon", false);
990 version(leds
) installerUI
.setSelection("ledsIcon", false);
991 version(leds
) installerUI
.setSelection("ledsDEditor", false);
993 version(gtkDtest
) installerUI
.setSensitive("gtkDTestsIcon", false);
994 version(leds
) installerUI
.setSensitive("ledsIcon", false);
995 version(leds
) installerUI
.setSensitive("ledsDEditor", false);
999 class TestPanel
: UserPanel
1003 //bool installed = false;
1004 public this(InstallerUI installerUI
)
1008 public bool complete()
1012 public bool selected()
1018 public char[] getName()
1022 public Widget
getWidget()
1026 vbox
= new VBox(false, 2);
1042 private void testButtonAction(Button button
)
1044 switch ( button
.getActionName() )
1048 writefln("testButtonAction going for %s", button
.getActionName());
1049 std
.process
.system(button
.getActionName());
1055 private void setup()
1057 Label label
= new Label(
1058 "Installation is complete\n"
1059 ~"press Exit to quit the installer\n"
1060 ~"or execute the test programs"
1062 vbox
.packStart(label
, false, false, 2);
1068 if ( installerUI
.getSelection("gtkDTests") )
1070 button
= new Button("gtkD Tests");
1071 vbox
.packStart(newButton(button
, "helpGtkDTests"), false, false, 2);
1072 button
.setActionName(installerUI
.getDirectory("gtkDDevHome")~"/gtkDTests");
1073 button
.addOnClicked(&testButtonAction
);
1078 if ( installerUI
.getSelection("gtkDglSimple") )
1080 button
= new Button("SimpleGL test");
1081 button
.setActionName(installerUI
.getDirectory("gtkDDevHome")~"/SimpleGL");
1082 button
.addOnClicked(&testButtonAction
);
1083 vbox
.packStart(newButton(button
, "helpSimpleGLTest"), false, false, 2);
1085 if ( installerUI
.getSelection("gtkDglShapes") )
1087 button
= new Button("ShapesGL test");
1088 button
.setActionName(installerUI
.getDirectory("gtkDDevHome")~"/ShapesGL");
1089 button
.addOnClicked(&testButtonAction
);
1090 vbox
.packStart(newButton(button
, "helpShapesGLTest"), false, false, 2);
1095 if ( installerUI
.getSelection("leds") )
1097 button
= new Button("Leds");
1098 button
.setActionName(installerUI
.getDirectory("ledsHome")~"/leds");
1099 button
.addOnClicked(&testButtonAction
);
1100 vbox
.packStart(newButton(button
, "helpLedsTest"), false, false, 2);
1107 MainInstaller mainInstaller
;
1109 int main(char[][] args
)
1117 GtkD
.initMultiThread(args
);
1119 mainInstaller
= new MainInstaller();