%WRITTEN BY  CAGDAS

%SHOWS LOGIN SCREEN
function varargout = GUI_showLoginScreen(varargin)
% GUI_SHOWLOGINSCREEN MATLAB code for GUI_showLoginScreen.fig
%      GUI_SHOWLOGINSCREEN, by itself, creates a new GUI_SHOWLOGINSCREEN or raises the existing
%      singleton*.
%
%      H = GUI_SHOWLOGINSCREEN returns the handle to a new GUI_SHOWLOGINSCREEN or the handle to
%      the existing singleton*.
%
%      GUI_SHOWLOGINSCREEN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_SHOWLOGINSCREEN.M with the given input arguments.
%
%      GUI_SHOWLOGINSCREEN('Property','Value',...) creates a new GUI_SHOWLOGINSCREEN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_showLoginScreen_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_showLoginScreen_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_showLoginScreen

% Last Modified by GUIDE v2.5 05-Dec-2013 01:38:38

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_showLoginScreen_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_showLoginScreen_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GUI_showLoginScreen is made visible.
function GUI_showLoginScreen_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to GUI_showLoginScreen (see VARARGIN)
%axes(handles.axes1)
imshow('se_sqa.jpg')
%imshow(handles.axes1,'C:\Users\Mridula\Pictures\5-23-2009\Bamboo.jpg')
% Choose default command line output for GUI_showLoginScreen
handles.output = hObject;
handles.ctrl = varargin{1};

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI_showLoginScreen wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_showLoginScreen_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function tbUserName_Callback(hObject, eventdata, handles)
% hObject    handle to tbUserName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tbUserName as text
%        str2double(get(hObject,'String')) returns contents of tbUserName as a double


% --- Executes during object creation, after setting all properties.
function tbUserName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tbUserName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function tbPassword_Callback(hObject, eventdata, handles)
% hObject    handle to tbPassword (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tbPassword as text
%        str2double(get(hObject,'String')) returns contents of tbPassword as a double


% --- Executes during object creation, after setting all properties.
function tbPassword_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tbPassword (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in btnLogin.
function btnLogin_Callback(hObject, eventdata, handles)
% hObject    handle to btnLogin (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
userName = get(handles.tbUserName,'String');
password = get(handles.tbPassword,'UserData');
set(handles.tbPassword,'String','');
set(handles.tbPassword,'UserData','');
handles.ctrl.login(userName,password);


% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on key press with focus on tbPassword and none of its controls.
function tbPassword_KeyPressFcn(hObject, eventdata, handles)
% Function to replace all characters in the password edit box with
% asterisks

password = get(hObject,'Userdata');

key = eventdata.Key;

switch key
    case 'backspace'
        password = password(1:end-1); % Delete the last character in the password
    case 'return'  % This cannot be done through callback without making tab to the same thing
        gui = getappdata(0,'logindlg');
        btnLogin_Callback(hObject, eventdata, handles);
        return;
    case 'tab'  % Avoid tab triggering the OK button
        gui = getappdata(0,'logindlg');
        uicontrol(gui.OK);
    case 'escape'
        % do nothing
       ;
    otherwise
        password = [password eventdata.Character]; % Add the typed character to the password
end

SizePass = size(password); % Find the number of asterisks
if SizePass(2) > 0
    asterisk(1,1:SizePass(2)) = '*'; % Create a string of asterisks the same size as the password
    set(hObject,'String',asterisk) % Set the text in the password edit box to the asterisk string
else
    set(hObject,'String','')
end

set(hObject,'Userdata',password);
% Store the password in its current state
% % hObject    handle to tbPassword (see GCBO)
% % eventdata  structure with the following fields (see UICONTROL)
% %	Key: name of the key that was pressed, in lower case
% %	Character: character interpretation of the key(s) that was pressed
% %	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% % handles    structure with handles and user data (see GUIDATA)
% a =eventdata.Character;
% 
% if(a >32)
%     s = get(handles.tbPassword,'String');
%     for i =1:length(s)
%         if(s(i) ~= '*') 
%             handles.password(i) = s(i);
%             s(i) = '*';
%         end
%     end
%     set(handles.tbPassword,'String',s);
%     handles.password
% end
    
