Class: ServerLogSettings

Inherits:
ServerLogSettingsDlg show all
Defined in:
lib/ServerLogSettings.rb

Instance Attribute Summary

Attributes inherited from ServerLogSettingsDlg

#cancelBtn, #editBtn, #groupBox3, #hostNameList, #logFile, #name, #newBtn, #okBtn, #removeBtn, #searchBtn, #setAsDefaultBtn, #textLabel1, #textLabel2, #textLabel4

Instance Method Summary collapse

Methods inherited from ServerLogSettingsDlg

#cancelBtnClicked

Constructor Details

#initialize(settings, parent = nil, name = nil) ⇒ ServerLogSettings

Returns a new instance of ServerLogSettings.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ServerLogSettings.rb', line 20

def initialize(settings, parent = nil, name = nil)
  super(parent, name)

  connect(@hostNameList, SIGNAL('selectionChanged(QListViewItem*)'),
      SLOT('selectionChanged(QListViewItem*)'))
  connect(@hostNameList, SIGNAL('clicked(QListViewItem*)'),
      SLOT('itemClicked(QListViewItem*)'))

  @settings = settings
  @name.text = settings.name
  @logFile.text = settings.logFile
  settings.hostNames.each do |hostName|
    item = Qt::ListViewItem.new(@hostNameList)
    item.setText(0, hostName)
    item.setText(1, settings.default == hostName ? '<-' : '')
  end

  enableListEditButtons(false)

  show
end

Instance Method Details

#askForHostName(oldName = nil) ⇒ Object



42
43
44
45
46
47
# File 'lib/ServerLogSettings.rb', line 42

def askForHostName(oldName = nil)
  dlg = HostNameDlg.new(self)
  dlg.hostName.text = oldName if oldName
  dlg.show
  dlg.exec == Qt::Dialog.Accepted ? dlg.hostName.text : nil
end

#editBtnClickedObject



64
65
66
67
68
69
# File 'lib/ServerLogSettings.rb', line 64

def editBtnClicked
  return if !@hostNameList.selectedItem
  if hostName = askForHostName(@hostNameList.selectedItem.text(0))
    @hostNameList.selectedItem.setText(0, hostName)
  end
end

#itemClicked(item) ⇒ Object



139
140
141
# File 'lib/ServerLogSettings.rb', line 139

def itemClicked(item)
  enableListEditButtons(false) unless item
end

#newBtnClickedObject



55
56
57
58
59
60
61
62
# File 'lib/ServerLogSettings.rb', line 55

def newBtnClicked
  if hostName = askForHostName
    noDefaultYet = hostNameList.firstChild == nil
    item = Qt::ListViewItem.new(@hostNameList)
    item.setText(0, hostName)
    item.setText(1, noDefaultYet ? '<-' : '')
  end
end

#okBtnClickedObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ServerLogSettings.rb', line 86

def okBtnClicked
  # Make sure the selected name is ok
  if @name.text.empty?
    Qt::MessageBox.warning(self, "No name set",
        "You must specify a name.", Qt::MessageBox.Ok, 0)
    return
  end
  $globals.serverLogFiles.each do |slf|
    if slf.name == @name.text && slf != @settings
      Qt::MessageBox.warning(self, "Name Conflict",
          "There is already another log with this name\n" +
          "Please choose a different name.", Qt::MessageBox.Ok, 0)
      return
    end
  end

  # Check the log file
  if @logFile.text.empty?
    Qt::MessageBox.warning(self, "No file set",
        "You must specify a log file.", Qt::MessageBox.Ok, 0)
    return
  end
  unless File.exist?(@logFile.text)
    Qt::MessageBox.warning(self, "Invalid log file",
        "The specified log file does not exist.", Qt::MessageBox.Ok, 0)
    return
  end

  # There must be at least one server URL
  unless @hostNameList.firstChild
    Qt::MessageBox.warning(self, "No URL defined",
        "You must specify at least one base URL of the server.",
        Qt::MessageBox.Ok, 0)
    return
  end

  @settings.name = @name.text
  @settings.logFile = @logFile.text
  hostNames = []
  it = Qt::ListViewItemIterator.new(@hostNameList)
  while (it.current)
    hostNames << it.current.text(0)
    @settings.default = it.current.text(0) if it.current.text(1) == '<-'
    it += 1
  end
  @settings.hostNames = hostNames
  accept
end

#removeBtnClickedObject



71
72
73
74
# File 'lib/ServerLogSettings.rb', line 71

def removeBtnClicked
  @hostNameList.selectedItem.dispose if @hostNameList.selectedItem
  enableListEditButtons(false) unless hostNameList.selectedItem
end

#searchBtnClickedObject



49
50
51
52
53
# File 'lib/ServerLogSettings.rb', line 49

def searchBtnClicked
  fileName = Qt::FileDialog.getOpenFileName("", "", self, "Select Log File",
                                            "Choose an Apache Log File");
  @logFile.setText(fileName)
end

#selectionChanged(item) ⇒ Object



135
136
137
# File 'lib/ServerLogSettings.rb', line 135

def selectionChanged(item)
  enableListEditButtons(true)
end

#setAsDefaultBtnClickedObject



76
77
78
79
80
81
82
83
84
# File 'lib/ServerLogSettings.rb', line 76

def setAsDefaultBtnClicked
  return if !@hostNameList.selectedItem
  it = Qt::ListViewItemIterator.new(@hostNameList)
  while (it.current)
    it.current.setText(1, it.current == @hostNameList.selectedItem ?
        '<-' : '')
    it += 1
  end
end