WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Edit TC-Exit Options  (Read 18405 times)

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Edit TC-Exit Options
« Reply #30 on: February 09, 2019, 01:20:04 PM »
w00t!

That did it.

Thanks a million!

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Edit TC-Exit Options
« Reply #31 on: February 09, 2019, 02:21:40 PM »
Hi TomyTurbos
Looks like additions to  .profile  probably need to be added above this section of the file in order to be seen:
Code: [Select]
TERMTYPE=`/usr/bin/tty`
[ ${TERMTYPE:5:3} == "tty" ] && (
[ ! -f /etc/sysconfig/Xserver ] ||
[ -f /etc/sysconfig/text ] ||
[ -e /tmp/.X11-unix/X0 ] ||
startx
)

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Edit TC-Exit Options
« Reply #32 on: February 09, 2019, 05:55:38 PM »
You did a great job, Rich.  I guess we're all still learning...

Thinking forward, it would be cool if what you started grew into a package or script where one can select or change the default behavior, but don't rush to do that on my account.  I got what I needed for the moment.  It would be a cool feature though.

I haven't yet looked into the ACPI for how to change the power button's behavior, mostly because I'm still wrapped up in the webserver portion of my project.  But at some point I'll get back to that, and I'm sure to call on your expertise at that time.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Edit TC-Exit Options
« Reply #33 on: February 09, 2019, 09:01:53 PM »
Hi TomyTurbos
You did a great job, Rich.  ...
Thank you.

Quote
... Thinking forward, it would be cool if what you started grew into a package or script where one can select or change the default behavior, but don't rush to do that on my account. ...
Since  exittc  is part of  Xprogs.tcz  I'd prefer to see if my changes will be accepted. I've finalized the patch and added a few
comments to the code. The patch file is attached here and has also been submitted to  http://patches.tinycorelinux.net/.

This is what it looks like:
Code: [Select]
--- exittc.cxx.old 2019-02-07 00:24:19.498731367 +0000
+++ exittc.cxx 2019-02-09 20:28:21.511600298 +0000
@@ -115,6 +115,37 @@
 Fl_Return_Button *btnOK=(Fl_Return_Button *)0;
 
 int main(int argc, char **argv) {
+
+// Variables used to override default radio button for shutdown.
+int shutdownDefault=1, rebootDefault=0, promptDefault=0;
+string exitpromptDefault;
+
+if ( getenv("EXITPROMPT"))
+{ // If environmental variable EXITPROMPT is set user wants to override default behavior.
+ shutdownDefault=0;
+ exitpromptDefault  = getenv("EXITPROMPT");
+ if (exitpromptDefault == "shutdown")
+ {
+ action = 1;
+ shutdownDefault=1;
+ }
+ else
+ if (exitpromptDefault == "reboot")
+ {
+ action = 2;
+ rebootDefault=1;
+ }
+ else
+ if (exitpromptDefault == "prompt")
+ {
+ action = 3;
+ promptDefault=1;
+ }
+ else // Invalid value for EXITPROMPT so revert to default behavior.
+ shutdownDefault=1;
+}
+
+
   setlocale(LC_ALL, "");
 bindtextdomain("tinycore","/usr/local/share/locale");
 textdomain("tinycore");
@@ -125,17 +156,19 @@
       { Fl_Round_Button* o = new Fl_Round_Button(25, 10, 85, 15, gettext("Shutdown"));
         o->type(102);
         o->down_box(FL_ROUND_DOWN_BOX);
-        o->value(1);
+        o->value(shutdownDefault); // Setting this to non-zero turns it on.
         o->callback((Fl_Callback*)btn_callback, (void*)("shutdown"));
       } // Fl_Round_Button* o
       { Fl_Round_Button* o = new Fl_Round_Button(25, 30, 65, 15, gettext("Reboot"));
         o->type(102);
         o->down_box(FL_ROUND_DOWN_BOX);
+        o->value(rebootDefault); // Setting this to non-zero turns it on.
         o->callback((Fl_Callback*)btn_callback, (void*)("reboot"));
       } // Fl_Round_Button* o
       { btnExitPrompt = new Fl_Round_Button(25, 50, 110, 15, gettext("Exit to Prompt"));
         btnExitPrompt->type(102);
         btnExitPrompt->down_box(FL_ROUND_DOWN_BOX);
+        btnExitPrompt->value(promptDefault); // Setting this to non-zero turns it on.
         btnExitPrompt->callback((Fl_Callback*)btn_callback, (void*)("prompt"));
       } // Fl_Round_Button* btnExitPrompt
       o->end();

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Edit TC-Exit Options
« Reply #34 on: February 09, 2019, 10:58:33 PM »
Saul Goodman!

('s all good, man)

I understand why you did this the way you did and I don't mind being a guinea pig, especially if it's a feature I need/want.  I try to give back to the community in any way I can, which is why I make an effort to recap on questions I have answers for such as my 'lighty' thread.

I still don't really get how to apply a patch, but I'll get there eventually.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Edit TC-Exit Options
« Reply #35 on: February 09, 2019, 11:36:54 PM »
Hi TomyTurbos
... I still don't really get how to apply a patch, ...
That's why I provided the  .tar.bz2  file, much simpler. A patch file merely documents how a file was changed. It is typically used
to submit source code changes. There is a program called  patch  that can read the  .patch  file and apply the changes to the
original source code. At any rate, the  .patch  file is really intended for someone like curaga or Juanito to apply to the original
source code if the changes are accepted.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11040
Re: Edit TC-Exit Options
« Reply #36 on: February 10, 2019, 05:16:53 AM »
The FLTK projects are generated from the fluid files, so a patch against a cxx file would just vanish on the next build. Please edit the fluid file (in fluid). The changes themselves look ok.
The only barriers that can stop you are the ones you create yourself.

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Edit TC-Exit Options
« Reply #37 on: February 10, 2019, 11:21:52 AM »
... At any rate, the  .patch  file is really intended for someone like curaga or Juanito to apply to the original source code if the changes are accepted.

Roger that!

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Edit TC-Exit Options
« Reply #38 on: February 10, 2019, 12:32:26 PM »
Hi curaga
... a patch against a cxx file would just vanish on the next build. ...
Yeah, I hate it when that happens.  :)  Attached is the diff of the fluid file. Here's what it looks like:
Code: [Select]
--- exittc.fl.old 2019-02-10 08:50:39.097576708 +0000
+++ exittc.fl 2019-02-10 10:56:37.304126234 +0000
@@ -1,41 +1,57 @@
 # data file for the Fltk User Interface Designer (fluid)
-version 1.0110
-i18n_type 1
-i18n_include <libintl.h>
-i18n_function gettext
-header_name {.h}
+version 1.0304
+i18n_type 1
+i18n_include <libintl.h>
+i18n_function gettext
+header_name {.h}
 code_name {.cxx}
-decl {// (c) Robert Shingledecker 2008-2010} {}
+decl {// (c) Robert Shingledecker 2008-2010} {private local
+}
 
-decl {\#include <cstdlib>} {}
+decl {\#include <cstdlib>} {private local
+}
 
-decl {\#include <iostream>} {}
+decl {\#include <iostream>} {private local
+}
 
-decl {\#include <stdio.h>} {}
+decl {\#include <stdio.h>} {private local
+}
 
-decl {\#include <string>} {}
+decl {\#include <string>} {private local
+}
 
-decl {\#include <fstream>} {}
+decl {\#include <fstream>} {private local
+}
 
-decl {\#include <FL/fl_message.H>} {}
+decl {\#include <FL/fl_message.H>} {private local
+}
 
-decl {\#include <locale.h>} {}
+decl {\#include <locale.h>} {private local
+}
 
-decl {\#include <unistd.h>} {}
+decl {\#include <unistd.h>} {private local
+}
 
-decl {\#include <string.h>} {}
+decl {\#include <string.h>} {private local
+}
 
-decl {using namespace std;} {}
+decl {using namespace std;} {private local
+}
 
-decl {string backup_device="", command;} {}
+decl {string backup_device="", command;} {private local
+}
 
-decl {int action=1;} {}
+decl {int action=1;} {private local
+}
 
-decl {bool backup=true;} {}
+decl {bool backup=true;} {private local
+}
 
-decl {string commandStr = "exitcheck.sh ";} {}
+decl {string commandStr = "exitcheck.sh ";} {private local
+}
 
-decl {string cmdline, actionStr, backup_options, backup_command;} {}
+decl {string cmdline, actionStr, backup_options, backup_command;} {private local
+}
 
 Function {btn_callback(Fl_Widget*, void*userdata)} {open return_type {static void}
 } {
@@ -114,7 +130,7 @@
     exit(0);
   } 
 }} {}
-}
+}
 
 Function {} {open
 } {
@@ -128,13 +144,13 @@
     Fl_Group {} {open
       xywh {25 10 115 70}
     } {
-      Fl_Round_Button {} {
+      Fl_Round_Button btnExitShutdown {
         label Shutdown
         user_data {"shutdown"}
         callback btn_callback
         xywh {25 10 85 15} type Radio down_box ROUND_DOWN_BOX value 1
       }
-      Fl_Round_Button {} {
+      Fl_Round_Button btnExitReboot {
         label Reboot
         user_data {"reboot"}
         callback btn_callback
@@ -180,6 +196,35 @@
       xywh {100 150 70 20}
     }
   }
+  code {// Environmental value used to override default radio button for shutdown.
+// Valid values are "shutdown", "reboot", or "prompt"
+string exitpromptDefault;
+
+if ( getenv("EXITPROMPT"))
+{ // If environmental variable EXITPROMPT is set user wants to override default behavior.
+ exitpromptDefault  = getenv("EXITPROMPT");
+ btnExitShutdown->value(0); // Clear current default.
+ if (exitpromptDefault == "shutdown")
+ {
+ action = 1;
+ btnExitShutdown->value(1);
+ }
+ else
+ if (exitpromptDefault == "reboot")
+ {
+ action = 2;
+ btnExitReboot->value(1);
+ }
+ else
+ if (exitpromptDefault == "prompt")
+ {
+ action = 3;
+ btnExitPrompt->value(1);
+ }
+ else // Invalid value for EXITPROMPT so revert to default behavior.
+ btnExitShutdown->value(1);
+}} {selected
+  }
   code {ifstream backup_device_file("/etc/sysconfig/backup_device");
 if ( backup_device_file.is_open())
 {
@@ -249,6 +294,5 @@
 if (cmdline.find("xonly") != string::npos) btnExitPrompt->hide();
 
 window->show(argc, argv);
-btnOK->take_focus();} {selected
-  }
-}
+btnOK->take_focus();} {}
+}
Doing this through fluid forced me to alter my method slightly. I named the 2 unnamed radio buttons and overrode the default
directly by using ButtonName->value.

I didn't know if you want diffs on the cxx and header files so I've attached them as well.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11040
Re: Edit TC-Exit Options
« Reply #39 on: February 11, 2019, 02:54:26 AM »
Applied, thanks.
The only barriers that can stop you are the ones you create yourself.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14788
Re: Edit TC-Exit Options
« Reply #40 on: February 11, 2019, 06:48:33 AM »
Xprogs updated in tc-10.x x86 repo - please test.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Edit TC-Exit Options
« Reply #41 on: February 11, 2019, 10:25:29 AM »
Hi TomyTurbos
OK, time to finalize the changes. First remove the  exittc  program you compiled:
Code: [Select]
rm ~/.local/bin/exittcEnter  y  when it asks you to confirm.

Next update your system:
Code: [Select]
tce-audit builddb
tce-audit updatedeps
tce-audit fetchmissing
tce-update

Click on the  Exit  icon. Click  Reboot  and then  OK. When the machine comes back up, open a terminal and enter this command:
Code: [Select]
tc@box:~$ which exittc
/usr/local/bin/exittc
tc@box:~$
Confirm you got the same response.

Finally, click on the  Exit  icon. It should be defaulting to  Reboot  again.

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Edit TC-Exit Options
« Reply #42 on: February 12, 2019, 07:22:03 PM »
Xprogs updated in tc-10.x x86 repo - please test.

I'm curious to know why apache2.4 is a dependency.

Just trying to understand this.

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Edit TC-Exit Options
« Reply #43 on: February 12, 2019, 07:23:46 PM »
Hi TomyTurbos
OK, time to finalize the changes. First remove the  exittc  program you compiled:
Code: [Select]
rm ~/.local/bin/exittcEnter  y  when it asks you to confirm.

Next update your system:
Code: [Select]
tce-audit builddb
tce-audit updatedeps
tce-audit fetchmissing
tce-update

Click on the  Exit  icon. Click  Reboot  and then  OK. When the machine comes back up, open a terminal and enter this command:
Code: [Select]
tc@box:~$ which exittc
/usr/local/bin/exittc
tc@box:~$
Confirm you got the same response.

Finally, click on the  Exit  icon. It should be defaulting to  Reboot  again.

Thanks.  I had already applied the update via Apps and all is well.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Edit TC-Exit Options
« Reply #44 on: February 12, 2019, 08:10:29 PM »
Hi TomyTurbos
Xprogs updated in tc-10.x x86 repo - please test.
I'm curious to know why apache2.4 is a dependency.

Just trying to understand this.
What make you think  apache  is a dependency? According to this:
http://tinycorelinux.net/10.x/x86/tcz/Xprogs.tcz.dep
the dependencies are:
Code: [Select]
Xlibs.tcz
fltk-1.3.tcz
imlib2-bin.tcz