class Qparol

password: rL8CQ3C9pMBfDn9epQyjX6nNycKP3ZGh

Public Class Methods

new() click to toggle source
Calls superclass method
# File bin/qparol, line 11
def initialize
  super

  initWindow
  initMenu
  initView
  resetDatabaseVar

  show
end

Public Instance Methods

about_me() click to toggle source

aboutMenu

# File bin/qparol, line 119
def about_me
  Qt::MessageBox.information self, 'About Me', 'I am a French Coder, my name is Ogromny.'
end
about_qparol() click to toggle source
# File bin/qparol, line 123
def about_qparol
  Qt::MessageBox.information self, 'About QParol', 'A GUI in Qt for Parol.'
end
add_row() click to toggle source
# File bin/qparol, line 242
def add_row
  current_row = @tableWidget.rowCount
  @tableWidget.setRowCount current_row + 1
end
close() click to toggle source
# File bin/qparol, line 209
def close
  # @tableWidget
  @tableWidget.setRowCount 0

  resetDatabaseVar

  # fileMenu enableds
  @fileMenu_new.enabled = true
  @fileMenu_load.enabled = true
  @fileMenu_save.enabled = false
  @fileMenu_close.enabled = false

  # window
  setWindowTitle 'QParol'
end
contextMenuEvent(event) click to toggle source

window

# File bin/qparol, line 226
def contextMenuEvent event
  # Actions
  menu_addRow      = Qt::Action.new '&Add row', self
  menu_removeRows  = Qt::Action.new '&Remove row(s)', self

  # menu
  menu = Qt::Menu.new self
  menu.addAction menu_addRow
  menu.addAction menu_removeRows
  menu.popup Qt::Cursor.pos

  # connects
  connect menu_addRow,     SIGNAL('triggered()'), self, SLOT('add_row()')
  connect menu_removeRows, SIGNAL('triggered()'), self, SLOT('remove_rows()')
end
initMenu() click to toggle source
# File bin/qparol, line 34
def initMenu
  # Actions
  @fileMenu_new   = Qt::Action.new '&New', self
  @fileMenu_load  = Qt::Action.new '&Load', self
  @fileMenu_save  = Qt::Action.new '&Save', self
  @fileMenu_close = Qt::Action.new '&Close', self
  fileMenu_exit   = Qt::Action.new '&Exit', self

  # Shortcuts
  @fileMenu_new.setShortcut   'Ctrl+N'
  @fileMenu_load.setShortcut  'Ctrl+L'
  @fileMenu_save.setShortcut  'Ctrl+S'
  @fileMenu_close.setShortcut 'Ctrl+C'
  fileMenu_exit.setShortcut   'Ctrl+Q'

  # Enableds
  @fileMenu_save.enabled  = false
  @fileMenu_close.enabled = false

  # fileMenu
  fileMenu = menuBar.addMenu '&File'
  fileMenu.addAction @fileMenu_new
  fileMenu.addAction @fileMenu_load
  fileMenu.addAction @fileMenu_save
  fileMenu.addAction @fileMenu_close
  fileMenu.addSeparator
  fileMenu.addAction fileMenu_exit

  # Connect
  connect @fileMenu_new,   SIGNAL('triggered()'), self,                     SLOT('new()')
  connect @fileMenu_load,  SIGNAL('triggered()'), self,                     SLOT('parol_load()')
  connect @fileMenu_save,  SIGNAL('triggered()'), self,                     SLOT('parol_save()')
  connect @fileMenu_close, SIGNAL('triggered()'), self,                     SLOT('close()')
  connect fileMenu_exit,   SIGNAL('triggered()'), Qt::Application.instance, SLOT('quit()')

  # Actions
  aboutMenu_me     = Qt::Action.new '&Me',     self
  aboutMenu_QParol = Qt::Action.new '&QParol', self
  aboutMenu_Qt     = Qt::Action.new '&Qt',     self

  # aboutMenu
  aboutMenu = menuBar.addMenu '&About'
  aboutMenu.addAction aboutMenu_me
  aboutMenu.addAction aboutMenu_QParol
  aboutMenu.addAction aboutMenu_Qt

  # Shortcuts
  aboutMenu_me.setShortcut     'Ctrl+M'
  aboutMenu_QParol.setShortcut 'Ctrl+P'
  aboutMenu_Qt.setShortcut     'Ctrl+Alt+Q'

  # Connects
  connect aboutMenu_me,     SIGNAL('triggered()'), self,                     SLOT('about_me()')
  connect aboutMenu_QParol, SIGNAL('triggered()'), self,                     SLOT('about_qparol()')
  connect aboutMenu_Qt,     SIGNAL('triggered()'), Qt::Application.instance, SLOT('aboutQt()')
end
initView() click to toggle source
# File bin/qparol, line 91
def initView
  @tableWidget = Qt::TableWidget.new

  # Columns
  @tableWidget.setColumnCount 4
  @tableWidget.setHorizontalHeaderLabels %w(Program Username Password Comment)
  @tableWidget.setColumnWidth 0, 200
  @tableWidget.setColumnWidth 1, 160
  @tableWidget.setColumnWidth 2, 180
  @tableWidget.horizontalHeader.setStretchLastSection true

  # Selection
  @tableWidget.setSelectionBehavior Qt::AbstractItemView::SelectRows

  setCentralWidget @tableWidget
end
initWindow() click to toggle source
# File bin/qparol, line 22
def initWindow
  setWindowTitle 'QParol'

  setMinimumSize 800, 400

  # centerWindow
  screenGeometry = Qt::Application::desktop.screenGeometry
  x = (screenGeometry.width - width) / 2
  y = (screenGeometry.height - height) / 2
  move x, y
end
new() click to toggle source

fileMenu

# File bin/qparol, line 128
def new
  # DatabaseVar
  @database_file     = Qt::FileDialog::getSaveFileName self, 'Save database', ENV['HOME'], 'Parol Database (*)'
  @database_password = Qt::InputDialog::getText self, 'Database password', 'Password:'
  @database          = Parol::Database.new @database_file, @database_password

  # @tableWidget
  @tableWidget.setRowCount 0

  # fileMenu enableds
  @fileMenu_new.enabled = false
  @fileMenu_load.enabled = false
  @fileMenu_save.enabled = true
  @fileMenu_close.enabled = true

  # window
  setWindowTitle "QParol::#{@database_file}"

rescue Parol::BadPasswordLength
  Qt::MessageBox.critical self, 'Database password', 'Password must be 32 of length'
end
parol_load() click to toggle source
# File bin/qparol, line 150
def parol_load
  # databaseVar
  @database_file     = Qt::FileDialog::getOpenFileName self, 'Load database', ENV['HOME'], 'Parol Database (*)'
  @database_password = Qt::InputDialog::getText self, 'Database password', 'Password:'
  @database          = Parol::Database.new @database_file, @database_password

  # load accounts into @tableWidget
  @database.accounts do |account|
    currentRow = @tableWidget.rowCount
    @tableWidget.setRowCount currentRow + 1

    # 4 columns
    0.upto 3 do |column|
      symbol = @parol_sym[column]
      item   = Qt::TableWidgetItem.new account[symbol]

      @tableWidget.setItem currentRow, column, item
    end
  end

  # fileMenu enableds
  @fileMenu_new.enabled   = false
  @fileMenu_load.enabled  = false
  @fileMenu_save.enabled  = true
  @fileMenu_close.enabled = true

  # window
  setWindowTitle "QParol::#{@database_file}"

rescue Parol::BadPasswordLength
  Qt::MessageBox.critical self, 'Database password', 'Password must be 32 of length'
rescue Parol::DecryptionFailed
  Qt::MessageBox.critical self, 'Database password', "Wrong password\nOr\nWrong file"
end
parol_save() click to toggle source
# File bin/qparol, line 185
def parol_save
  rowCount = @tableWidget.rowCount - 1
  data     = []

  # all rows
  0.upto rowCount do |row|
    parol = {}

    # 4 columns
    0.upto 3 do |column|
      item   = @tableWidget.item row, column
      symbol = @parol_sym[column]

      parol[symbol] = item ? item.text : ''
    end

    data << parol
  end

  @database.save data

  Qt::MessageBox.information self, 'Success', 'Successfully saved the database !'
end
remove_rows() click to toggle source
# File bin/qparol, line 247
def remove_rows
  select   = @tableWidget.selectionModel
  selected = select.selectedRows

  reponse = Qt::MessageBox.warning self, 'Are you sure ?', 'Do you really want to delete selected rows ?', Qt::MessageBox::Yes|Qt::MessageBox::No

  selected.each do |index|
    row = index.row
    @tableWidget.removeRow row
  end if reponse == 16384 # YES
end
resetDatabaseVar() click to toggle source
# File bin/qparol, line 108
def resetDatabaseVar
  @database          = nil::NilClass
  @database_file     = ''
  @database_password = ''
end