2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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
.duitLogo
;
38 private import gtk
.Duit
;
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 gtk
.gtktypes
;
54 private import gtk
.SizeGroup
;
56 private import gdk
.Event
;
57 private import std
.stdio
;
59 private import std
.c
.stdlib
;
60 private import std
.string
;
64 void setUserPanel(UserPanel panel
);
65 void addSelection(char[] id
, CheckButton check
);
66 CheckButton
getSelectionButton(char[] id
);
67 bool getSelection(char[] id
);
68 void setSelection(char[] id
, bool state
);
69 void setSensitive(char[] id
, bool state
);
71 void addDirectory(char[] id
, Entry entry
);
72 char[] getDirectory(char[] id
);
73 void setDirectory(char[] id
, char[] value
);
79 public class MainInstaller
: MainWindow
, InstallerUI
94 UserPanel
[] userPanels
;
95 UserPanel currentUserPanel
;
96 CheckButton
[char[]] selections
;
97 Entry
[char[]] directories
;
99 int movingDirection
; // going back or next, 0=don't know
103 super("Duit and Leds installer");
110 public void addSelection(char[] id
, CheckButton check
)
112 selections
[id
] = check
;
115 public CheckButton
getSelectionButton(char[] id
)
118 if ( id
in selections
)
120 check
= selections
[id
];
125 public bool getSelection(char[] id
)
127 if ( id
in selections
)
129 return cast(bool)selections
[id
].getActive();
133 public void setSelection(char[] id
, bool active
)
135 if ( id
in selections
)
137 selections
[id
].setActive(active
);
140 public void setSensitive(char[] id
, bool active
)
142 if ( id
in selections
)
144 selections
[id
].setSensitive(active
);
148 public void addDirectory(char[] id
, Entry entry
)
150 directories
[id
] = entry
;
152 public char[] getDirectory(char[] id
)
154 if ( id
in directories
)
156 return directories
[id
].getText();
160 public void setDirectory(char[] id
, char[] value
)
162 if ( id
in directories
)
164 return directories
[id
].setText(value
);
168 public void nextPanel()
172 setUserPanel(notebook
.getCurrentPage());
175 public void prevPanel()
177 movingDirection
= -1;
179 setUserPanel(notebook
.getCurrentPage());
182 private import gtk
.HSeparator
;
185 topBox
= new HBox(false, 2);
186 leftBox
= new VBox(false, 7);
187 tasksBox
= new VBox(false, 7);
188 mainBox
= new VBox(false, 2);
189 notebook
= new Notebook
;
190 notebook
.setShowTabs(false);
191 notebook
.setSizeRequest(400,300);
192 buttonBox
= HButtonBox
.createActionBox();
194 exitButton
= makeButton(null, StockID
.QUIT
, "Exit", "exit");
195 buttonBox
.packStart(Alignment
.west(exitButton
), true, true, 7);
197 backButton
= makeButton(buttonBox
, StockID
.GO_BACK
, "Back", "back");
198 nextButton
= makeButton(buttonBox
, StockID
.GO_FORWARD
, "Next", "next");
199 installButton
= makeButton(buttonBox
, StockID
.OK
, "Install", "install");
201 // Button logo = new Button();
202 // logo.setImage(getDuitLogo());
203 // logo.addOnButtonPress(&logoClicked);
204 // logo.setRelief(ReliefStyle.NONE);
205 // logo.setFocusOnClick(false);
207 mainBox
.packStart(Alignment
.west(getDuitLogo()), false, false, 2);
208 mainBox
.packStart(notebook
, true, true, 2);
209 mainBox
.packStart(buttonBox
, false, false, 2);
211 topBox
.packStart(new Frame(tasksBox
,""), false, false, 2);
212 topBox
.packStart(mainBox
, true, true, 2);
217 private import gtk
.PopupBox
;
219 private int logoClicked(GdkEventButton
* event
, Widget widget
)
222 PopupBox
.information(this, "Help with the graphics design is apreciated", "DuitLogo");
226 private Button
makeButton(ButtonBox box
,StockID id
, char[] label
, char[] action
)
228 Button button
= new Button();
229 button
.setActionName(action
);
231 button
.setImage(new Image(id
, IconSize
.BUTTON
));
232 button
.setLabel(label
);
235 box
.packStart(button
, false, false, 7);
237 button
.addOnClicked(&userActions
);
241 private void addPanels()
243 addPanel(new SelectionsPanel(this));
244 version(duitdev
)addPanel(new DevPanel(this));
245 version(leds
) addPanel(new LedsPanel(this));
246 version(compiler
) addPanel(new MainCompilerPanel(this));
247 addPanel(new LocalPanel(this));
248 addPanel(new InstallPanel(this));
251 CheckButton
[char[]] tasksList
;
253 private void addPanel(UserPanel userPanel
)
255 notebook
.appendPage(userPanel
.getWidget(), userPanel
.getName());
257 HBox hbox
= new HBox(false, 1);
258 CheckButton check
= new CheckButton();
259 hbox
.packStart(check
, false, false, 4);
261 hbox
.packStart(Alignment
.west(new Label(userPanel
.getName())), false, false, 4);
262 tasksBox
.packStart(hbox
, false, false, 4);
263 tasksList
[userPanel
.getName()] = check
;
264 check
.setSensitive(false);
265 userPanels
~= userPanel
;
268 private void userActions(Button button
)
270 char[] action
= button
.getActionName();
291 writefln("userAction = %s", action
);
297 private void setUserPanel(uint number
)
299 if ( number
< userPanels
.length
)
301 UserPanel panel
= userPanels
[number
];
306 public void setUserPanel(UserPanel panel
)
308 if ( currentUserPanel
!is null )
310 currentUserPanel
.exited();
312 while ( !panel
.selected()
313 && movingDirection
!= 0
316 if ( movingDirection
> 0 )
326 backButton
.setSensitive(panel
.allowBack());
327 nextButton
.setSensitive(panel
.allowNext());
328 bool allowInstall
= true;
329 foreach ( UserPanel userPanel
; userPanels
)
331 if ( !userPanel
.complete() )
333 allowInstall
= false;
335 if ( userPanel
.getName
in tasksList
)
337 tasksList
[userPanel
.getName()].setActive(userPanel
.complete());
340 installButton
.setSensitive(allowInstall
);
341 currentUserPanel
= panel
;
347 InstallerUI installerUI
;
349 bool completed
= false;
353 abstract Widget
getWidget();
354 abstract char[] getName();
355 public this(InstallerUI installerUI
)
357 this.installerUI
= installerUI
;
360 public bool allowNext()
364 public bool allowBack()
368 public bool selected()
376 public bool complete()
381 protected HBox
newSelection(char[] selection
, char[] id
)
383 HBox box
= new HBox(false, 2);
385 Button button
= new Button(StockID
.HELP
, &userHelp
, true);
386 button
.setActionName(id
);
387 button
.setImage(new Image(StockID
.HELP
, IconSize
.MENU
));
388 CheckButton check
= new CheckButton(selection
, &userSelection
);
389 check
.setActionName(id
);
391 box
.packStart(button
, false, false, 2);
392 box
.packStart(check
, false, false, 2);
393 installerUI
.addSelection(id
, check
);
397 protected HBox
newDirectory(char[] label
, char[] id
, SizeGroup sizeGroup
)
399 HBox box
= new HBox(false, 2);
400 Button button
= new Button(StockID
.HELP
, &userHelp
, true);
401 button
.setActionName(id
);
402 button
.setImage(new Image(StockID
.HELP
, IconSize
.MENU
));
403 Entry entry
= new Entry();
405 box
.packStart(button
, false, false, 2);
406 Label l
= new Label(label
);
407 Alignment alig
= Alignment
.west(l
);
408 sizeGroup
.addWidget(alig
);
409 box
.packStart(alig
, false, false, 2);
410 box
.packStart(entry
, true, true, 2);
411 button
= new Button(StockID
.INDEX
, &userDirectory
);
412 button
.setActionName(id
);
413 button
.setLabel("Browse");
414 button
.setImage(new Image(StockID
.INDEX
, IconSize
.MENU
));
415 box
.packStart(button
, false, false, 2);
416 installerUI
.addDirectory(id
, entry
);
420 void userSelection(CheckButton check
)
422 switch ( check
.getActionName() )
426 bool active
= cast(bool)check
.getActive();
427 installerUI
.setSensitive("ledsDuit", active
);
428 installerUI
.setSensitive("ledsLeds", active
);
429 installerUI
.setSensitive("ledsDool", active
);
430 installerUI
.setSensitive("ledsDante", active
);
431 installerUI
.setSensitive("ledsPhobos", active
);
440 void userHelp(Button button
)
444 private import gtk
.FileChooserDialog
;
445 private import gtk
.FileChooser
;
446 void userDirectory(Button button
)
448 char[] id
= button
.getActionName();
449 char[] dir
= installerUI
.getDirectory(id
);
452 FileChooserDialog chooserDialog
= new FileChooserDialog(
455 FileChooserAction
.SELECT_FOLDER
457 FileChooser chooser
= chooserDialog
.getFileChooser();
458 chooser
.setCurrentFolder(dir
);
459 ResponseType response
= cast(ResponseType
)chooserDialog
.run();
460 if ( response
== ResponseType
.GTK_RESPONSE_OK
)
462 installerUI
.setDirectory(id
, chooser
.getCurrentFolder());
464 chooserDialog
.hide(); // is it released ?
469 class SelectionsPanel
: UserPanel
473 public this(InstallerUI installerUI
)
477 public char[] getName()
481 public Widget
getWidget()
485 vbox
= new VBox(false, 2);
491 public bool allowBack()
496 public bool selected()
504 vbox
.packStart(new Label("Select the components to install"), false, false, 14);
505 vbox
.packStart(newSelection("Install Duit", "duit"), false, false, 2);
506 version(duitdev
) vbox
.packStart(newSelection("Install Duit for development", "duitDev"), false, false, 2);
507 version(duitgl
) vbox
.packStart(newSelection("Install Duitgl", "duitgl"), false, false, 2);
508 version(duitdev
) version(duitgl
) vbox
.packStart(newSelection("Install Duitgl for development", "duiglDev"), false, false, 2);
509 version(leds
) vbox
.packStart(newSelection("Install Leds", "leds"), false, false, 2);
511 installerUI
.setSelection("duit", true);
512 version(duitdev
) installerUI
.setSelection("duitDev", true);
513 version(duitgl
) installerUI
.setSelection("duitgl", true);
514 version(duitdev
) version(duitgl
) installerUI
.setSelection("duiglDev", true);
515 version(leds
) installerUI
.setSelection("leds", true);
521 class DevPanel
: UserPanel
525 public this(InstallerUI installerUI
)
529 public char[] getName()
531 return "Development for Duit";
533 public Widget
getWidget()
537 vbox
= new VBox(false, 2);
543 public bool selected()
546 return installerUI
.getSelection("duitDev")
547 || installerUI
.getSelection("duitglDev");
552 vbox
.packStart(new Label("Select Duit modules"), false, false, 14);
553 version(difiles
) vbox
.packStart(newSelection("Duit .di files", "duitdi"), false, false, 2);
554 vbox
.packStart(newSelection("Duit source files", "duitSource"), false, false, 2);
555 vbox
.packStart(newSelection("DuitTests - general UI tests", "duitTests"), false, false, 2);
556 version(duitgl
) vbox
.packStart(newSelection("SimpleGL - simplest GL test", "duitglSimple"), false, false, 2);
557 version(duitgl
) vbox
.packStart(newSelection("ShapesGL - showing more of openGL integration", "duitglShapes"), false, false, 2);
559 version(difiles
) installerUI
.setSelection("duitdi", true);
560 installerUI
.setSelection("duitSource", true);
561 installerUI
.setSelection("duitTests", true);
562 version(duitgl
) installerUI
.setSelection("duitglSimple", true);
563 version(duitgl
) installerUI
.setSelection("duitglShapes", true);
570 class LedsPanel
: UserPanel
574 public this(InstallerUI installerUI
)
578 public char[] getName()
580 return "Leds projects";
582 public Widget
getWidget()
586 vbox
= new VBox(false, 2);
592 public bool selected()
595 return installerUI
.getSelection("leds");
600 vbox
.packStart(new Label("Select the leds projects to create"), false, false, 14);
601 vbox
.packStart(newSelection("Create a leds project for Duit", "ledsDuit"), false, false, 2);
602 vbox
.packStart(newSelection("Create a leds project for Leds", "ledsLeds"), false, false, 2);
603 vbox
.packStart(newSelection("Create a leds project for Dool", "ledsDool"), false, false, 2);
604 vbox
.packStart(newSelection("Create a leds project for Dante", "ledsDante"), false, false, 2);
605 vbox
.packStart(newSelection("Create a leds project for phobos", "ledsPhobos"), false, false, 2);
607 installerUI
.setSelection("ledsDuit", true);
608 installerUI
.setSelection("ledsLeds", true);
609 installerUI
.setSelection("ledsDool", true);
610 installerUI
.setSelection("ledsDante", true);
611 installerUI
.setSelection("ledsPhobos", true);
618 class MainCompilerPanel
: UserPanel
622 public this(InstallerUI installerUI
)
626 public char[] getName()
630 public Widget
getWidget()
634 vbox
= new VBox(false, 2);
640 public bool selected()
648 vbox
.packStart(new Label("Select your D compiler"), false, false, 14);
650 vbox
.packStart(new Label("For the installation"), false, false, 7);
651 vbox
.packStart(newSelection("Digital Mars DMD", "instalCompilerDMD"), false, false, 2);
652 vbox
.packStart(newSelection("gnu D GDC", "installCompilerGDC"), false, false, 2);
654 vbox
.packStart(new Label("For your leds projects"), false, false, 7);
655 vbox
.packStart(newSelection("Digital Mars DMD", "ledsCompilerDMD"), false, false, 2);
656 vbox
.packStart(newSelection("gnu D GDC", "ledsCompilerGDC"), false, false, 2);
658 installerUI
.setSelection("instalCompilerDMD", true);
659 installerUI
.setSelection("installCompilerGDC", false);
660 version(leds
) installerUI
.setSelection("ledsCompilerDMD", true);
661 version(leds
) installerUI
.setSelection("ledsCompilerGDC", false);
663 installerUI
.setSensitive("instalCompilerDMD", false);
664 installerUI
.setSensitive("installCompilerGDC", false);
665 version(leds
) installerUI
.setSensitive("ledsCompilerDMD", false);
666 version(leds
) installerUI
.setSensitive("ledsCompilerGDC", false);
673 class LocalPanel
: UserPanel
680 public this(InstallerUI installerUI
)
683 sizeGroup
= new SizeGroup(SizeGroupMode
.HORIZONTAL
);
686 home
= std
.string
.toString(getenv("HOMEPATH"));
690 home
= std
.string
.toString(getenv("HOME"));
694 public char[] getName()
699 private import std
.path
;
700 private import std
.file
;
702 private bool validDir(char[] dir
)
704 bool valid
= dir
.length
> 0;
708 public bool validDMDHome()
711 char[] dir
= installerUI
.getDirectory("dmdHome");
712 valid
= validDir(dir
);
717 version(Win32
) char[] dmd
= std
.path
.join(std
.path
.join(dir
,"bin"), "dmd.exe");
718 else char[] dmd
= std
.path
.join(std
.path
.join(dir
,"bin"), "dmd");
719 std
.file
.isfile(dmd
);
722 char[] dm
= std
.path
.join(std
.path
.join(dir
,"..\\dm"),"bin");
723 char[] link
= std
.path
.join(dm
, "link.exe");
724 std
.file
.isfile(link
);
725 char[] lib
= std
.path
.join(dm
, "lib.exe");
726 std
.file
.isfile(lib
);
728 else char[] link
= std
.path
.join(std
.path
.join(dir
,"bin"), "dmd");
731 catch ( FileException pe
)
744 // char[] userChoice;
748 // bool isDir(char[] dir)
753 // ok = cast(bool)std.file.isfile(dir);
755 // catch ( FileException fe )
762 // bool exists(char[] fileName)
767 // ok = cast(bool)std.file.exists(fileName);
769 // catch ( FileException fe )
777 public char[] guessDMDHome()
786 guess
= std
.path
.join(home
, "dmd");
791 public char[] guessGtkHome()
796 guess
= "\\Program Files\\Common Files\\GTK\\2.0\\bin";
805 public char[] guessDuitLibHome()
810 guess
= "\\Program Files\\Common Files\\GTK\\2.0\\bin";
814 guess
= "/home/ruimt/usr/lib";
819 public char[] guessDuitDevHome()
824 guess
= "\\testRelease";
828 guess
= std
.path
.join(home
, "devel/D/testInstall/Duit1");
833 public char[] guessLedsHome()
838 guess
= "\\Program Files\\Common Files\\org\\dsource\\leds";
842 guess
= std
.path
.join(home
, "devel/D/Leds1");
848 public bool selected()
855 completed
= validDMDHome();
862 completed
= installerUI
.getDirectory("duitDevHome").length
> 0;
869 completed
= installerUI
.getDirectory("ledsHome").length
> 0;
875 completed
= installerUI
.getDirectory("gtkHome").length
> 0;
879 completed
= installerUI
.getDirectory("duitLibHome").length
> 0;
884 public Widget
getWidget()
888 vbox
= new VBox(false, 2);
895 vbox
.packStart(new Label("Select the paths for installation"), false, false, 14);
896 vbox
.packStart(newDirectory("DMD home", "dmdHome", sizeGroup
), false, false, 2);
897 vbox
.packStart(newDirectory("Gtk lib home", "gtkHome", sizeGroup
), false, false, 2);
898 vbox
.packStart(newDirectory("Duit lib home", "duitLibHome", sizeGroup
), false, false, 2);
899 version(duitdev
) vbox
.packStart(newDirectory("Duit dev home", "duitDevHome", sizeGroup
), false, false, 2);
900 version(leds
) vbox
.packStart(newDirectory("leds home", "ledsHome", sizeGroup
), false, false, 2);
902 installerUI
.setDirectory("dmdHome", guessDMDHome());
903 installerUI
.setDirectory("gtkHome", guessGtkHome());
904 installerUI
.setDirectory("duitLibHome", guessDuitLibHome());
905 version(duitdev
) installerUI
.setDirectory("duitDevHome", guessDuitDevHome());
906 version(leds
) installerUI
.setDirectory("ledsHome", guessLedsHome());
910 class InstallPanel
: UserPanel
913 //bool installed = false;
914 public this(InstallerUI installerUI
)
918 public bool selected()
923 public char[] getName()
927 public Widget
getWidget()
931 vbox
= new VBox(false, 2);
944 Label label
= new Label(
945 "Thank you for installing Duit\n"
946 ~"press Install to continue"
948 vbox
.packStart(label
, true, true, 2);
950 version(duittest
) vbox
.packStart(newSelection("Create desktop icon for duit tests", "duitTestsIcon"), false, false, 2);
951 version(leds
) vbox
.packStart(newSelection("Create desktop icon for leds", "ledsIcon"), false, false, 2);
952 version(leds
) vbox
.packStart(newSelection("set leds as your D editor", "ledsDEditor"), false, false, 2);
954 version(duittest
) installerUI
.setSelection("duitTestsIcon", false);
955 version(leds
) installerUI
.setSelection("ledsIcon", false);
956 version(leds
) installerUI
.setSelection("ledsDEditor", false);
958 version(duittest
) installerUI
.setSensitive("duitTestsIcon", false);
959 version(leds
) installerUI
.setSensitive("ledsIcon", false);
960 version(leds
) installerUI
.setSensitive("ledsDEditor", false);
964 MainInstaller mainInstaller
;
966 int main(char[][] args
)
974 Duit
.initMultiThread(args
);
976 mainInstaller
= new MainInstaller();