camera-control-webcam-switc.../main.pas

152 lines
3.5 KiB
ObjectPascal
Raw Normal View History

2020-01-23 11:35:57 +01:00
unit Main;
{$mode objfpc}{$H+}
2020-01-23 18:44:44 +01:00
{$warnings off}
{$hints off}
2020-01-23 11:35:57 +01:00
2020-01-23 11:38:42 +01:00
// Created at 23th of January 2020 by Linuxer (https://gitlab.com/psposito), from scratch with Free Pascal
2020-01-23 11:35:57 +01:00
interface
uses
2020-01-26 11:56:51 +01:00
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Menus, Unix,
unitAbout;
2020-01-23 11:35:57 +01:00
type
{ TForm1 }
TForm1 = class(TForm)
MenuItem1 : TMenuItem;
MenuItem2 : TMenuItem;
MenuItem3 : TMenuItem;
MenuItem4 : TMenuItem;
2020-01-26 11:56:51 +01:00
MenuItem5 : TMenuItem;
2020-01-23 11:35:57 +01:00
PopupMenu1 : TPopupMenu;
TrayIcon1 : TTrayIcon;
procedure FormCreate(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
procedure MenuItem2Click(Sender: TObject);
procedure MenuItem3Click(Sender: TObject);
procedure MenuItem4Click(Sender: TObject);
2020-01-26 11:56:51 +01:00
procedure MenuItem5Click(Sender: TObject);
procedure TrayIcon1Click(Sender: TObject);
2020-01-23 11:35:57 +01:00
private
public
end;
var
Form1 : TForm1;
2020-01-26 11:56:51 +01:00
//FormAbout : TFormAbout;
2020-01-23 11:35:57 +01:00
S : LongInt;
n : Integer;
2020-01-23 11:35:57 +01:00
HasPassword : Boolean;
Password : String;
implementation
{$R *.frm}
{ TForm1 }
procedure CameraOn;
begin
2020-01-26 11:56:51 +01:00
S := fpsystem(concat('echo ', Password, ' | sudo -S modprobe uvcvideo'));
if (S <> 0) then
begin
ShowMessage('Incorrect password');
HasPassword := false;
end;
2020-01-23 11:35:57 +01:00
end;
procedure CameraOff;
begin
2020-01-26 11:56:51 +01:00
S := fpsystem(concat('echo ', Password, ' | sudo -S modprobe -r uvcvideo'));
if (S <> 0) then
begin
ShowMessage('Incorrect password');
HasPassword := false;
end;
2020-01-23 11:35:57 +01:00
end;
procedure AskPassword;
begin
Password := PasswordBox('Authorization Needed / User Input','Please Enter Password');
2020-01-23 11:35:57 +01:00
HasPassword := True;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
2020-01-23 18:44:44 +01:00
S := fpsystem('echo off');
2020-01-23 11:35:57 +01:00
HasPassword := false;
application.showmainform := false;
TrayIcon1.Hint := 'Camera Switch';
TrayIcon1.ShowIcon := True;
TrayIcon1.Show;
end;
procedure TForm1.MenuItem1Click(Sender: TObject);
begin
if HasPassword then
begin
CameraOn;
end
else
begin
AskPassword;
CameraOn;
end;
end;
procedure TForm1.MenuItem2Click(Sender: TObject);
begin
if HasPassword then
begin
CameraOff;
end
else
begin
AskPassword;
CameraOff;
end;
end;
procedure TForm1.MenuItem3Click(Sender: TObject);
begin
TrayIcon1.Hide;
2020-01-23 18:44:44 +01:00
PopupMenu1.Free;
TrayIcon1.Free;
2020-01-23 11:35:57 +01:00
Halt (0);
end;
procedure TForm1.MenuItem4Click(Sender: TObject);
begin
HasPassword := false;
ShowMessage('Password has been forgotten');
end;
2020-01-26 11:56:51 +01:00
procedure TForm1.MenuItem5Click(Sender: TObject);
begin
FormAbout.Label1.Caption:='Project';
FormAbout.Label2.Caption:='Developer';
FormAbout.Label3.Caption:='Licence';
FormAbout.ListBox1.Items.Clear;
FormAbout.ListBox1.Items.Add('Camera Control On/Off Switch for Linux is a');
FormAbout.ListBox1.Items.Add('LGPL2 Free Pascal Project with LCL components,');
FormAbout.ListBox1.Items.Add('completely developed from scratch, at 23th, of');
FormAbout.ListBox1.Items.Add('January 2020 by Linuxer パスカリス スポシト');
FormAbout.Show;
end;
procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
PopupMenu1.PopUp;
end;
2020-01-26 11:56:51 +01:00
end.